AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 How to Convert a SqlDataReader To a DataTable or DataSet in Asp.Net?
Posted by Moderator1 on  10/11/2008 8:42:29 AM 12548 Views
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.

Post New Tips/Tricks View all Tips/Tricks

Featured Resources:
Building a Web Application Security Program
Learn how to build a pragmatic web application security program that constrains costs while still providing effective security.
Integrating Silverlight 4 with SharePoint 2010 - Free 42 Page Sample Chapter
A free sample chapter from Packt Enterprise's book: Microsoft Silverlight 4 and SharePoint 2010 Integration.
100% Free Subscription until Stock lost.View complete list.
Sponsored by