Y ADO.NET does not return a simple ReadOnly Query data as a DataTable though we need most of the times a Single Table of Data from DataBase ? Similar to DataAdapter returning a DataSet ! Or can we Typecast DataReader objecft as a DataTable straightaway / n
RSS
Hi All, After we moved from JSP and started developing a web application in ASP.NET, the DataAdapter is used for all sort of operations like insert/update/delete for a table. But, most of the time we need to query the data from db for a Table/View and the returned
data will be a Single Table of data. Though ADO.NET has a facility of keeping such a data in DataTable, y does ADO.NET have not provided a way to return a DataTable. Similar to DataAdapter returning a DataSet. Its like a mix up of DataReader and DataAdapter
with Read Only component returning DataTable. Or, please let me know whether there exists a way to convert a DataReader into a DataTable WITHOUT any looping of col. names and rows and inserting it into DataTable ? Or, can we write a Class and override DataReader
/ DataAdapter to return data as a DataTable ? Yours, Sankar.B
Though ADO.NET has a facility of keeping such a data in DataTable, y does ADO.NET have not provided a way to return a DataTable. Similar to DataAdapter returning a DataSet.
When you call DataAdapter.Fill(dataset); the tables returned are stored in the dataset - if your query only returns one table, it will only contain one table - and can be accessed from DataSet.Tables. e.g. DataTable myTable = myDataSet.Tables[0]; [It could
be done this way so you can query one table, or many, with the same constructs. That's just a guess though]
Hi, Tx for ur info. Im also aware of populating the returned single/multiple result sets in the dataset as tables 0,1,etc. and populating a single query result set in a DataTable using the Fill method. But, using the DataAdapter is a costlier use for a SELECT
query / forward only. It should be like a DataReader, but it does not provide a direct facility to return the result set as a DataTable. Ive tried all the 3 options available with DataReader and converting it into a single DataTable by looping the col names
and rows of data, filling a single DataTable using Fill and filling a DataSet using Fill for a table of more than 1000 rows. All the 3 options are slow. But, comparitively DataAdapter.Fill(DataTable) is ok now. But, i dont want it tobe done with DataAdapter,
it should be a DataReader returning a DataTable directly. Also, my doubt is DataReader returns the MetaData as a DataTable where it doesnot provide a facility to return the rows of data as a DataTable. But, looping it and converting it as DT takes more time
than DataAdapter.Fill(DataTable). So, is it possible to get a DataTable from a DataReader directly anyway by our custom class or overriding DataReader. I dont find any doc also reg. this. Pl help me out. Yours, Sankar.B
What would the point be of DataReader returning a DataTable? Then it would just be functioning as a DataAdapter. The DataReader was designed specifically to provide the best performance when all you need is a forward-only read-only data view. What is wrong
with using DataAdapter.Fill(DataTable)? If what you are looking for is the schema of the table, rather than the contents of the entire table, try DataAdapter.FillSchema(DataTable). Other than that, you'll have to specify why you can't use DataAdapter.Fill(DataTable)
before we can help you find another solution. AutoFed
Hi AutoFed, "What would the point be of DataReader returning a DataTable? Then it would just be functioning as a DataAdapter." : But, DataAdapter is not specifically meant to return a Read only/ Forward only data table. "The DataReader was designed specifically
to provide the best performance when all you need is a forward-only read-only data view." : For this reason only, we expect DataReader should return a DataTable as a Result. Because most of the times , normal Query for a table to display data is Forward only
/ Read only. So, its natural to expect DataReader to return a DataTable apart from its Read method to retrive the data. "What is wrong with using DataAdapter.Fill(DataTable)?" : Since DataAdapter not meant for Retrival / Update it again in DB, its not an ideal
for a Read only/Forward only retrival of data and for read only retrival of more amount of data. "If what you are looking for is the schema of the table, rather than the contents of the entire table, try DataAdapter.FillSchema(DataTable)." : Im not looking
for it. Hope its clear now. "Other than that, you'll have to specify why you can't use DataAdapter.Fill(DataTable) before we can help you find another solution." : We need a Read only / Forward only retrival of data and return it in the form of a DataTable.
So, can anyone pl. tell us is there any way to make DataReader to return a DataTable without iterating the col. names and rows and constructing the DataTable. Yours, Sankar.B
I'm still not clear on your problem, but it sounds like maybe you are concerned that using DataAdapter.Fill is somehow inefficient for reading data. But even if DataReader did return a DataTable as a result,
there would be no difference between that and the DataAdapter.Fill. The only way to retrieve data from a data source is to execute SQL queries; the DataReader stores one row at a time, the DataAdapter retrieves and stores the entire contents of the query
result. What other possibility is there? What is it that you want to happen that ASP.NET does not provide? If your only goal is to create a read-only DataTable, instead of the editable DataTable provided by the DataAdapter, that would be no more "efficient"
than an editable DataTable: the data still has to be retrieved, stored, and accessed. AutoFed
>> ...meant to return a Read only/ Forward only data table Read the definition of a DataTable in your documentation PLEASE. DataTable is a representation of an entire subset of data from a table. It is addressed using array indexes. It is NOT cursor
driven. There is NOT a "current record" concept with a DataTable, therefore "read only/forward only" cannot and does not apply. >>
Since DataAdapter not meant for Retrival / Update it again in DB... Say What?!? Again please read your documentation. DataAdapter IS a mechanism for retrieval and update of data in the database. >>
...retrival of data and return it in the form of a DataTable. Then you have no choice but to use a DataAdapter! This is EXACTLY what the DataAdapter does - in fact, I believe it internally uses a DataReader to actually populate the DataTable. >>
...return a DataTable without iterating the col. names and rows and constructing the DataTable You already have been given this information (Use a DataAdapter), however you are choosing to ignore it.
Hi AutoFed, "I'm still not clear on your problem, but it sounds like maybe you are concerned that using DataAdapter.Fill is somehow inefficient for reading data. " : Yes. DataAdapter is meant for Query and Update data and not for Read Only purpose, i believe.
Also, as u told below, its a real disconnected data fetches data at one shot and give it as DataTable. "But even if DataReader did return a DataTable as a result, there would be no difference between that and the DataAdapter.Fill. " : I agree. Pl. continue...
"The only way to retrieve data from a data source is to execute SQL queries; " : Yes. "the DataReader stores one row at a time" : Im not aware or clear on this. Can u pl. explain this how ? Which will clear my doubt i feel. "the DataAdapter retrieves and stores
the entire contents of the query result. " & "What other possibility is there? What is it that you want to happen that ASP.NET does not provide? If your only goal is to create a read-only DataTable, instead of the editable DataTable provided by the DataAdapter,
that would be no more "efficient" than an editable DataTable: the data still has to be retrieved, stored, and accessed." : So, DataAdapter.Fill do the one what im expecting. Pl. tell me how DataReader retrives the data each row and gives us when we iterate
it using the Read method. I thought it will fetch all the data from the DB and keeps it inmemory and gives us when we iterate using the Read method. Whereas, DataAdapter will fetch row by row and fills the datatable. Yours, Sankar.B
A datareader is not disconnected. It's a server-side, forward only, read only cursor. It keeps the connection alive and only retrieves a row when you call read.
jinishans
Member
220 Points
44 Posts
Y ADO.NET does not return a simple ReadOnly Query data as a DataTable though we need most of the ...
Aug 01, 2003 04:18 AM|LINK
sfbayling
Member
10 Points
2 Posts
Re: Y ADO.NET does not return a simple ReadOnly Query data as a DataTable though we need most of ...
Aug 01, 2003 11:35 AM|LINK
Stephen Vaki...
Contributor
2540 Points
508 Posts
Re: Y ADO.NET does not return a simple ReadOnly Query data as a DataTable though we need most of ...
Aug 01, 2003 04:11 PM|LINK
jinishans
Member
220 Points
44 Posts
Re: Y ADO.NET does not return a simple ReadOnly Query data as a DataTable though we need most of ...
Aug 02, 2003 05:23 AM|LINK
autofed
Participant
1789 Points
357 Posts
Re: Y ADO.NET does not return a simple ReadOnly Query data as a DataTable though we need most of ...
Aug 03, 2003 05:50 AM|LINK
jinishans
Member
220 Points
44 Posts
Re: Y ADO.NET does not return a simple ReadOnly Query data as a DataTable though we need most of ...
Aug 03, 2003 09:57 AM|LINK
autofed
Participant
1789 Points
357 Posts
Re: Y ADO.NET does not return a simple ReadOnly Query data as a DataTable though we need most of ...
Aug 03, 2003 06:14 PM|LINK
krome
Member
190 Points
38 Posts
Re: Y ADO.NET does not return a simple ReadOnly Query data as a DataTable though we need most of ...
Aug 03, 2003 06:17 PM|LINK
MCSD, MCDBA, MCAD, CIC
jinishans
Member
220 Points
44 Posts
Re: Y ADO.NET does not return a simple ReadOnly Query data as a DataTable though we need most of ...
Aug 04, 2003 05:43 AM|LINK
Stephen Vaki...
Contributor
2540 Points
508 Posts
Re: Y ADO.NET does not return a simple ReadOnly Query data as a DataTable though we need most of ...
Aug 04, 2003 01:58 PM|LINK