Best viewed in IE 7 or Firefox 3.
You are using: Unknown 0
You are here > Blog
Mar 3

Written by: Michael Kubarycz
Tuesday, March 03, 2009 9:10 PM 

Provided by: http://www.aspdotnetcodes.com/ReadTips_Convert_SqlDataReader_To_DataTable_DataSet.aspx

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

Tags:

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 
 
Search Blog