Reputation: 9
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();
}
Upvotes: 0
Views: 3062
Reputation: 3360
Depending what exactly you expect the type of hhh
to be, you could do something like
hhh = dt.AsEnumerable().ToArray();
which would give you an array of DataRows
hhh = dt.AsEnumerable().Select(row => row.ItemArray).ToArray();
which would give you a jagged array - an array of arrays of object
, one array for each row
Upvotes: 1
Reputation: 3154
Try this:
string[] hhh = new string[dt.Columns.Count];
for (int i = 0; i < dt.Columns.Count; i++)
{
hhh[i] = dt.Columns[i].ToString();
}
Upvotes: 0
Reputation: 4596
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++;
}
Upvotes: 0