2013-06-03 71 views
0

有沒有什麼方法可以將訪問表中的數據顯示給某些特定的列。例如。 表具有以下數據 BCODE TCode1的Slot1 TCode2時隙2 TCode3插槽 BATCH1 T1 10:00 12:00 T2
Batch2 T1 08:00 09:00 T2 T3 11:30 Batch3 T1 08:00 10:00 T2 T3 11 :00是否有可能將數據放在datagridview的特定列中

而我的datagridview有以下列 BatchCode 08:00 08:30 09:00 09:30 10:00 10:30 11:00 11:30 12:00 12:30等等upto 20: 00 我想在16:00 T2下在18:00和t3下在20:00顯示T1 手段輸出應該是這樣的東西

BatchCode 08:00 08:30 09:00 09:30 10: 00 10:30 11:00 11:30 12:0 0 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; 

回答

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; 
    } 
相關問題