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();
     }
4

3 回答 3

1

根据您期望的类型hhh,您可以执行类似的操作

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

这会给你一个 DataRows 数组

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

这会给你一个锯齿状数组 - 数组的数组object,每行一个数组

于 2013-07-17T09:07:49.120 回答
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++;
         }
于 2013-07-17T09:05:31.800 回答
0

尝试这个:

string[] hhh = new string[dt.Columns.Count];
for (int i = 0; i < dt.Columns.Count; i++)
{
    hhh[i] = dt.Columns[i].ToString();
}
于 2013-07-17T09:12:00.000 回答