.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> ADO.NET >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Data read to Data table conversion

Posted By:nishithraj       Posted Date: November 27, 2009    Points: 10    Category: ADO.NET    URL: http://www.dotnetspark.com  

Data read to Data table conversion.

In many scenarios, we may require to convert data reader to data table. Connecting to data base is not a good way to achieve that. So we can do it by a trick as follows.

string ConStr= 'Call the connection string'
objCon= new SqlConnection(ConStr);
SqlCommand cmd = new SqlCommand('Some Query', objCon);
SqlDataReader objRead = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataTable objDt = new DataTable();
objDt.Load(objRead );

Here objDt.Load will load all the data contains from the reader to the data table objDt


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend