DataSet -> DataReader

D

Dave Cook

Is it possible to get a DataReader object from a DataSet/DataTable ? If so
would it
be disconnected ? in other words could I return a populated DataReader
object from a class that contains a DataSet ?
 
M

Miha Markic [MVP C#]

Hi Dave,

Huh?
DataReader is just a sort of forward only readonly cursor.
Why would you need a DataReader from DataSet?
 
D

Dave Cook

Hi Miha

I have written a collection class that returns data from a database table.
I would like to add a number of methods to the class that will also return
the data in a variety of usefull formats as the data will be used in a
variety of ways by different applications.

Some of the methods I have so far are:

SelectAllAsDataSet
SelectAllAsDataTable
SelectAllAsDataView
SelectAllAsXML

I would like to also be able to SelectAllAsDataReader. As all the above
methods use the DataSet object, I create the DataSet in the constructor. I
was hoping to derive the DataReader from the existing DataSet rather than
populating both objects as the table could potentially be quite large.

Since looking more into it, i am not sure i can return a DataReader object
from my class as the DataReader requires a permanent connection to the DB
for the life of the object.

If you have any ideas on this I would be gratefull.

Regards

Dave.


Miha Markic said:
Hi Dave,

Huh?
DataReader is just a sort of forward only readonly cursor.
Why would you need a DataReader from DataSet?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Dave Cook said:
Is it possible to get a DataReader object from a DataSet/DataTable ? If so
would it
be disconnected ? in other words could I return a populated DataReader
object from a class that contains a DataSet ?
 
M

Miha Markic [MVP C#]

Hi Dave,

You will have to implement IDataReader interface in a class that behaves
like datareader .
However, I still can't see where it might be useful.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Dave Cook said:
Hi Miha

I have written a collection class that returns data from a database table.
I would like to add a number of methods to the class that will also return
the data in a variety of usefull formats as the data will be used in a
variety of ways by different applications.

Some of the methods I have so far are:

SelectAllAsDataSet
SelectAllAsDataTable
SelectAllAsDataView
SelectAllAsXML

I would like to also be able to SelectAllAsDataReader. As all the above
methods use the DataSet object, I create the DataSet in the constructor. I
was hoping to derive the DataReader from the existing DataSet rather than
populating both objects as the table could potentially be quite large.

Since looking more into it, i am not sure i can return a DataReader object
from my class as the DataReader requires a permanent connection to the DB
for the life of the object.

If you have any ideas on this I would be gratefull.

Regards

Dave.


Miha Markic said:
Hi Dave,

Huh?
DataReader is just a sort of forward only readonly cursor.
Why would you need a DataReader from DataSet?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Dave Cook said:
Is it possible to get a DataReader object from a DataSet/DataTable ?
If
so
would it
be disconnected ? in other words could I return a populated DataReader
object from a class that contains a DataSet ?
 
D

Dave Cook

Hi Miha

I was thinking that a DataView would be handy for populating DataGrids etc
and a DataReader would provide better performance for populating ComboBoxes.

Am I wrong ?

As I may have mentioned earlier the the class will be shared and and used in
a variety of ways.



Miha Markic said:
Hi Dave,

You will have to implement IDataReader interface in a class that behaves
like datareader .
However, I still can't see where it might be useful.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Dave Cook said:
Hi Miha

I have written a collection class that returns data from a database table.
I would like to add a number of methods to the class that will also return
the data in a variety of usefull formats as the data will be used in a
variety of ways by different applications.

Some of the methods I have so far are:

SelectAllAsDataSet
SelectAllAsDataTable
SelectAllAsDataView
SelectAllAsXML

I would like to also be able to SelectAllAsDataReader. As all the above
methods use the DataSet object, I create the DataSet in the constructor. I
was hoping to derive the DataReader from the existing DataSet rather than
populating both objects as the table could potentially be quite large.

Since looking more into it, i am not sure i can return a DataReader object
from my class as the DataReader requires a permanent connection to the DB
for the life of the object.

If you have any ideas on this I would be gratefull.

Regards

Dave.


Miha Markic said:
Hi Dave,

Huh?
DataReader is just a sort of forward only readonly cursor.
Why would you need a DataReader from DataSet?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Is it possible to get a DataReader object from a DataSet/DataTable ? If
so
would it
be disconnected ? in other words could I return a populated DataReader
object from a class that contains a DataSet ?
 
M

Miha Markic [MVP C#]

Hi Dave,

Dave Cook said:
Hi Miha

I was thinking that a DataView would be handy for populating DataGrids etc
and a DataReader would provide better performance for populating
ComboBoxes.

Yes and no. DataReader might be used when retrieving data from database and
the data doesn't need to be persisted in DataTable.
If you already have data in datatable then DataReader is meaningless and
probably causes overhead.
Am I wrong ?

As I may have mentioned earlier the the class will be shared and and used in
a variety of ways.

Since your data is already in memory just use DataTable (when DataTable is
bind - in reallity DataTable.DefaultView is bound) or DataView as
datasource.
 
D

Dave Cook

of course, thanks for your help Miha.


Miha Markic said:
Hi Dave,


ComboBoxes.

Yes and no. DataReader might be used when retrieving data from database and
the data doesn't need to be persisted in DataTable.
If you already have data in datatable then DataReader is meaningless and
probably causes overhead.
used

Since your data is already in memory just use DataTable (when DataTable is
bind - in reallity DataTable.DefaultView is bound) or DataView as
datasource.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top