2013-07-17 39 views
0
 SqlDataAdapter da = new SqlDataAdapter("select d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16,d17,d18,d19,d20,d21,d22,d23,d24,d25,d26,d27,d28,d29,d30, name from jully where batch=" + "'" + s_batch + "'" + 
    "and semester=" + "'" + s_semester + "'" + "and shift=" + "'" + s_shift + "'"+"and rolno="+rolno, conn); 
    DataTable dt = new DataTable(); 
    conn.Open(); 
    da.Fill(dt); 

    for (int i = 0; i < dt.Columns.Count; i++) 
    { 
     hhh[i] = dt.Columns[].ToString(); 
    } 

回答

0
 SqlDataAdapter da = new SqlDataAdapter("select d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16,d17,d18,d19,d20,d21,d22,d23,d24,d25,d26,d27,d28,d29,d30, name from jully where batch=" + "'" + s_batch + "'" + 
     "and semester=" + "'" + s_semester + "'" + "and shift=" + "'" + s_shift + "'"+"and rolno="+rolno, conn); 
     DataTable dt = new DataTable(); 
     conn.Open(); 
     da.Fill(dt); 

     for (int i = 0; i < dt.rows.Count; i++) 
     { for (int j = 0; j < dt.columns.Count; j++) 
      hhh[k] = dt.rows[i][j].tostring(); 
k++; 
     } 
1

根據實際需要的內容的hhh類型是,你可以不喜歡

hhh = dt.AsEnumerable().ToArray(); 

這將使你數據行

hhh = dt.AsEnumerable().Select(row => row.ItemArray).ToArray(); 

陣列這將使您交錯數組 - 的object數組的數組,鄰NE陣列的每一行

0

嘗試這種情況:

string[] hhh = new string[dt.Columns.Count]; 
for (int i = 0; i < dt.Columns.Count; i++) 
{ 
    hhh[i] = dt.Columns[i].ToString(); 
} 
相關問題