You are not Logged in
Would you like to Login or Register

Today is: Friday, 21 November, 2008
Check this months hot topics

Convert a DataReader to a DataTable

When working with Datareaders one of the problems i sometimes come across is binding these to 3rd party controls. A lot of controls will not bind to a DataReader but nearly all of the alwaays bind to a DataTable. All of the functionlity already exists in the Framework you just need to know where to look.

So here is the simple way to convert a DataReader to a DataTable.

Create a class Inheriting from DataAdapter

   class DataReaderAdapter : System.Data.Common.DataAdapter
    {
        public int FillFromReader(DataTable dataTable, IDataReader dataReader)
        {
            return this.Fill(dataTable, dataReader);
        }
    }

Then to use it :

DataReaderAdapter dar = new DataReaderAdapter();
dar.FillFromReader(dataTable, dataReader);

Attached is a sample project showing the use of this.

kick it on DotNetKicks.com del.icio.us digg Mister Wong YahooMyWeb Reddit Furl Spurl blogmarks

Related Downloads

  • Sample Project
    This samples gets a Datareader of Products from the Northwind DB and converts this to a dataset
Greg Duffield Skype
Author : Greg Duffield
Published : Thursday, 13 July, 2006

Greg has too many years experience in developement from VB for DOS all the way through to Windows Workflow and LINQ while covering pretty much every technology in between. A complete MS evangelist he is now Director of the only MS Gold Partner IT services company in Norfolk. Wehere they are producing Web 2 Applications for various sectors, and are currently entering the Haulage industry with their latest product.

Add Comment

Enter your comment below and it will be submitted for moderation.

Your Name

Add Tag

Please enter tags for this article, seperated by semi-colon ;

View Tag's by : # articles | # views

Downloads

  • Sample Project
    This samples gets a Datareader of Products from the Northwind DB and converts this to a dataset