473,725 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9461
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@replytonews group.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@replytonews group.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.SelectComman d.CommandText = "SELECT * FROM TABLE2";
da.Fill(t2);
da.SelectComman d.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
4745
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 two different methods but when I try to populate them both no the same page I get "InvalidOperationException: Invalid attempt to FieldCount when reader is closed" WHY???
13
2493
by: Adie | last post by:
Hi, is this not possible? public DataSet getDimensions() { } public SqlDataReader getDimensions() { }
7
2362
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: ************************************************* public void Export2CSV(){
3
5888
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 combo's text property (what the user will see). Is this possible with a SqlDataReader? Thanks
4
2911
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 from the database. However, the two classes don't appear to have any common interfaces that would allow me to enumerate the fields. Yet, when you databind you can pass either of these classes (as well as many others) and .NET somehow knows how...
1
1429
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 a bit heavyweight for most purposes. I there some particular reason to stay away from sqldatareader?? I have managed to bind components using sqldatareader but digging up the information was quite hard.
8
1912
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 my localhost on my development machine. The database is on the web. When I run the app on the local machine, IE opens, loads my aspx page from localhost, and hangs. (Eventually I get a page cannot be displayed error.)
4
19786
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
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9113
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.