0

有什么方法可以将访问表中的数据显示到某些特定列。例如。表有以下数据 BCode TCode1 Slot1 TCode2 Slot2 TCode3 Slot Batch1 T1 10:00 T2 12:00
Batch2 T1 08:00 T2 09:00 T3 11:30 Batch3 T1 08:00 T2 10:00 T3 11:00

我的 datagridview 有以下列 BatchCode 08:00 08:30 09:00 09:30 10:00 10:30 11:00 11:30 12:00 12:30 等等直到 20:00 我想在下面显示 T1 16:00 T2 under 18:00 and t3 under 20:00 意思是输出应该是这样的

批号 08:00 08:30 09:00 09:30 10:00 10:30 11:00 11:30 12:00 12:30 B1 T1 T2 B2 T1 T2 T3 B3 T1 T2 T3

我尝试了很多方法,但没有达到输出。

            aCommand1 = new OleDbCommand("select * from weekly where bday like 'Sun'", main_connection);
        aAdapter1 = new OleDbDataAdapter(aCommand1);
        ds1 = new DataSet();
        aAdapter1.Fill(ds1, "app_info");
        int recCount = ds1.Tables[0].Rows.Count;
        dataGridView1.ColumnCount = 11;
        dataGridView1.Columns[0].Name = "Batch";
        dataGridView1.Columns[1].Name = "08:00";
        dataGridView1.Columns[2].Name = "08:30";
        dataGridView1.Columns[3].Name = "09:00";
        dataGridView1.Columns[4].Name = "09:30";
        dataGridView1.Columns[5].Name ="10:00";
        dataGridView1.Columns[6].Name ="10:30";
        dataGridView1.Columns[7].Name ="11:00";
        dataGridView1.Columns[8].Name ="11:30";
        dataGridView1.Columns[9].Name ="12:00";
        dataGridView1.Columns[10].Name ="12:30";
        for (int k = 0; k < recCount; k++)
        {
            int p_count = Convert.ToInt32(ds1.Tables[0].Rows[k][2].ToString());
            int col_count = 5;               // Column number of starting time slot
            string[] str = new string[p_count];
            int i = 0;
            for (int x = 1; x <= p_count; x++)
            {
                col_count += 2;   

                for (int m = 1; m < dataGridView1.ColumnCount; m++)
                {
                    if (dataGridView1.Columns[m].Name == ds1.Tables[0].Rows[k][col_count].ToString())
                    {
                        str[i] = ds1.Tables[0].Rows[k][col_count].ToString();
                        dataGridView1.Rows.Add(ds1.Tables[0].Rows[k][0].ToString(), str[i]);
                    }
                }
            }
        }
        dataGridView1.Columns[0].ReadOnly = true;
4

1 回答 1

0

经过 3 小时的漫长等待,当我没有从这里得到任何答案或回复时,我向cbsecsnip.in提出了这个问题,这段代码可以正常工作

for (int k = 0; k < recCount; k++)
        {
            int p_count = Convert.ToInt32(ds1.Tables[0].Rows[k][2].ToString());
            int col_count = 5;
            int teat = 4;
            string[] str = new string[p_count];
            int i = 0;
            string batchname = ds1.Tables[0].Rows[k][0].ToString();
            string[] teacher=new string[dataGridView1.ColumnCount];
            dataGridView1.Rows.Add(batchname);
            for (int x = 1; x <= p_count; x++)
            {
                for (int m = 1; m < dataGridView1.ColumnCount; m++)
                {
                    string colname = dataGridView1.Columns[m].Name;
                    string tablecoltime = ds1.Tables[0].Rows[k][col_count].ToString();
                    if (colname == tablecoltime)
                    {
                        teacher[m] = ds1.Tables[0].Rows[k][teat].ToString();
                        dataGridView1.Rows[k].Cells[m].Value = ds1.Tables[0].Rows[k][teat].ToString();
                    }
                    else
                    {
                        teacher[m] = "";
                    }
                }
                teat += 2; col_count += 2;
            }
        }
        dataGridView1.Columns[0].ReadOnly = true;
    }
于 2013-06-03T19:51:29.967 回答