To convert a SqlDataReader to DataTable or DataSet, use DataTable's Load method. Just look at the sample block of statements below.
string sql = "Select * from MyTable";
SqlCommand cmd = new SqlCommand(sql, MyConnection);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
//Load the SqlDataReader object to the DataTable object as follows.
dt.Load(dr);
Response.Write(dt.Rows.Count.ToString());
Thats it.
string sql = "Select * from MyTable";
SqlCommand cmd = new SqlCommand(sql, MyConnection);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
//Load the SqlDataReader object to the DataTable object as follows.
dt.Load(dr);
Response.Write(dt.Rows.Count.ToString());
Thats it.
No comments :
Post a Comment