473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

SqlDataReader vs. DataSet

Hi all,
My requirement is I need to have three different
recordsets open at the same time. Traversing through the 3
recordsets, I would check on the data and based on some
rules, return an object from my function.

Will it be efficient to use a SQLDataReader or a DataSet
for this situation? I understand from the documentation
that there can be only one SQLDataReader associated with a
connection open at a time. So, it seems like I can't have
3 SqlDataReaders open at the same time for my connection.
is SqlDataReader usable for these type of conditions
(unless I combine my 3 recordsets into a single recordset
by some means?)

Or can a DataSet be used? But I wouldn't be doing any
updates or deletes to any of those recordsets? Is it
useful to use a dataset at all?

I'm a beginner in C# and ADO.NET. Thanks for all your help.
Nov 15 '05 #1
4 9445
You can have three connections which would work. You can only traverse
forward with a DataReader. On the other hand, it sounds like you probably
want to sit all three queries in DataTables in a DataSet and use a
DataRelation to relate them if applicable.

Record size is also a big consderation. If you are talking about 1000
records, you probably will hardly be able to notice the performance
difference on most machiens. However, this depends on Table szie. but the
larger your query, the more pronounced the performance difference. Just
yesterday I was benchmarking queries and for pull 186,000 records from a
given table, it took almost half a minute with a DataAdapter. Using a
Reader it took just under 12 seconds. .

Also, joining tables server side in a query probably isn't the way to go.
You can use a datarelation object to relate tables and then you don't have
to pull over as much data. The differences here can be profound as well.

Hopefully this helps.

Bill
"lakshmi" <lm@replytonewsgroup.net> wrote in message
news:07****************************@phx.gbl...
Hi all,
My requirement is I need to have three different
recordsets open at the same time. Traversing through the 3
recordsets, I would check on the data and based on some
rules, return an object from my function.

Will it be efficient to use a SQLDataReader or a DataSet
for this situation? I understand from the documentation
that there can be only one SQLDataReader associated with a
connection open at a time. So, it seems like I can't have
3 SqlDataReaders open at the same time for my connection.
is SqlDataReader usable for these type of conditions
(unless I combine my 3 recordsets into a single recordset
by some means?)

Or can a DataSet be used? But I wouldn't be doing any
updates or deletes to any of those recordsets? Is it
useful to use a dataset at all?

I'm a beginner in C# and ADO.NET. Thanks for all your help.

Nov 15 '05 #2
Hi,

From the information you've given the DataSet sounds like the best choice.

The DataReader is like the forward-only/read-only Recordset in Classic ADO,
it is meant to be a "firehose". You get the data, you traverse it once, and
then you close it. It's great for filling a UI control like a listbox or
getting the data to be stored in custom business objects.

The DataSet is an in-memory database. You can get multiple resultsets (even
from different databases) and store them as DataTables inside the DataSet.

I hope this is enough to get you started. There are lots of resources online
that will give you more information on ADO.NET.

--
Rob Windsor
G6 Consulting
Toronto, Canada
"lakshmi" <lm@replytonewsgroup.net> wrote in message
news:07****************************@phx.gbl...
Hi all,
My requirement is I need to have three different
recordsets open at the same time. Traversing through the 3
recordsets, I would check on the data and based on some
rules, return an object from my function.

Will it be efficient to use a SQLDataReader or a DataSet
for this situation? I understand from the documentation
that there can be only one SQLDataReader associated with a
connection open at a time. So, it seems like I can't have
3 SqlDataReaders open at the same time for my connection.
is SqlDataReader usable for these type of conditions
(unless I combine my 3 recordsets into a single recordset
by some means?)

Or can a DataSet be used? But I wouldn't be doing any
updates or deletes to any of those recordsets? Is it
useful to use a dataset at all?

I'm a beginner in C# and ADO.NET. Thanks for all your help.

Nov 15 '05 #3
There are two options here, one of which works. The preferable one is to
open three different connections (which will be pooled by ADO.NET) and
associate a dataReader with each one. I doubt that will work, and I'm too
lazy to test it. The other option is to fill a DataTable for each of your
different recordsets, like this:

void somefunc() {
DataTable t1 = new DataTable();
DataTable t2 = new DataTable();
DataTable t3 = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM TABLE1",
someConnection);
da.Fill(t1);
da.SelectCommand.CommandText = "SELECT * FROM TABLE2";
da.Fill(t2);
da.SelectCommand.CommandText = "SELECT * FROM TABLE3";
da.Fill(t3);
}

Note that there's no need to use a DataSet here. A DataSet is more like a
collection of tables and rules relating those tables. Personally, I'd much
rather do my relations manually than mess with the crummy design support for
strongly typed DataKlotches. Sometimes (read usually) DataSets really just
aren't worth it.

Chris
Nov 15 '05 #4
Thanks. I'm talking about each recordset containing a
maximum of 60 records at a time. All the three recordsets
are basically retrieved from the same table for 3
different items. I thought I could create a SQL pivot view
that would return a single recordset (which would be a
combination) of all the 3 recordsets I've been mentioning.
(and then use a data reader to read from this recordset.)
This way I can use a single connection. Also, I don't know
if there is any overheads involved in using a dataset.
Kindly let me know if I am wrong.
Thanks for all of your replies.
-----Original Message-----
Hi all,
My requirement is I need to have three different
recordsets open at the same time. Traversing through the 3recordsets, I would check on the data and based on some
rules, return an object from my function.

Will it be efficient to use a SQLDataReader or a DataSet
for this situation? I understand from the documentation
that there can be only one SQLDataReader associated with aconnection open at a time. So, it seems like I can't have
3 SqlDataReaders open at the same time for my connection.
is SqlDataReader usable for these type of conditions
(unless I combine my 3 recordsets into a single recordset
by some means?)

Or can a DataSet be used? But I wouldn't be doing any
updates or deletes to any of those recordsets? Is it
useful to use a dataset at all?

I'm a beginner in C# and ADO.NET. Thanks for all your help.

.

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rod | last post by:
Thanks in advance. I have two listboxes on a single asp page. I am trying to use sqldatareader to populate both using two seperate sql stored procs. I can populate each box seperately using...
13
by: Adie | last post by:
Hi, is this not possible? public DataSet getDimensions() { } public SqlDataReader getDimensions() { }
7
by: Franck Diastein | last post by:
Hi, when I call ExportData I have this error: Invalid attempt to Read when reader is closed. Telling me that there's a problem with this line: while(_dataR.Read()){ Code:...
3
by: Neil Guyette | last post by:
Hello, Everyone, I'm trying to find information on how to populate a combo box using a SqlDataReader. I want to be able to set the value of the combo's value property different then the...
4
by: Michael Carr | last post by:
I have a function that populates a class with values from a database. I'd like to pass into the function either a SqlDataReader or a DataRow, depending on which mechanism I'm using to retrieve data...
1
by: me | last post by:
Why is SqlDataReader not present in visual studios Toolbox->Data where I find components like DataSet? Most examples in books and in vs.net are based on datasets but using disconnected tables seems...
8
by: Jeff | last post by:
Hi - I'm having trouble Databinding a SQLDataReader to a DataGrid control. I have an ASP.NET web page accessing a SQL database. I've used VS to build the app and stored it in a directory of...
4
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
Hi all I have a DataSet with one table filled. From this DataSet (DataTable), I need to create a SqlDataReader. Does anybody knows how to do this ? Is it possible ?? Thanks for any help.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.