473,327 Members | 1,920 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,327 software developers and data experts.

nTier question regarding DataSets and DataReaders

I know how this should be done in regards to nTier, but it seems a bit
inneficient, and was wondering if there's a solution that I havn't thought
of yet.

(I'm switching this loop to For Each Row as DataRow in.... to kill the one
int that's not needed.)

For intCount1 = 0 To
objData.DataSet.Tables("tblSecondaryNumbers").Rows .Count - 1
rowTemp = objData.DataSet.Tables("tblSecondaryNumbers").Rows (intCount1)
If intTempID <> rowTemp("PrimaryID") Then
intTempID = rowTemp("PrimaryID")
strDisplay += " arrSecondary[" & intTempID & "] = new Array();" & vbCr
End If
strDisplay += " arrSecondary[" & intTempID & "][" &
rowTemp("SecondaryID") & "] = """ & _
rowTemp("SecondaryNumber") & " - " & rowTemp("Type") & """;" & vbCr
Next
strDisplay += "</script>" & vbCr

That loop right there uses a DataSet that was passed back. However, it's
only used once, and it's Forward only. It seems logical that a DataReader
should be used instead, saving the resources.

Is using a DataSEt the best solution for it? I was thinking of sending back
an individual table, rather than create a DataSet. Wanted to throw it out
here to see if there was any better solution.
Nov 18 '05 #1
5 1157
Hi Ryan,

Microsoft has done a brilliant job of making people aware of the DataSet
class but a rather poor job of promoting the more lightweight data classes,
such as DataTable and DataReader. I'm not sure why, other than the fact that
there are a lot of lazy developers out there who just want their software to
run, and don't care all that much about performance, and are too lazy to
learn much more than one class if they can help it. The DataSet is a
one-size-fits-all class which can do much more than either DataTable or
DataReader. However, as you seem to notice, it also carries a much higher
resource cost. For example, a DataReader is used internally to populate a
DataSet. Obviously, the DataReader itself is much more compact. In addition,
a DataSet is not a table, but a rather complex container for multiple
DataTable objects. And in your code, you're only working with one DataTable
in the DataSet. So, a DataTable is more lightweight than a DataSet.

In your case, as you mentioned, you're moving through a single result set
forward-only. So, the most efficient solution for you would be to use a
DataReader.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Ryan Ternier" <rt******@icompasstech.com> wrote in message
news:eM**************@TK2MSFTNGP10.phx.gbl...
I know how this should be done in regards to nTier, but it seems a bit
inneficient, and was wondering if there's a solution that I havn't thought
of yet.

(I'm switching this loop to For Each Row as DataRow in.... to kill the one
int that's not needed.)

For intCount1 = 0 To
objData.DataSet.Tables("tblSecondaryNumbers").Rows .Count - 1
rowTemp = objData.DataSet.Tables("tblSecondaryNumbers").Rows (intCount1)
If intTempID <> rowTemp("PrimaryID") Then
intTempID = rowTemp("PrimaryID")
strDisplay += " arrSecondary[" & intTempID & "] = new Array();" & vbCr End If
strDisplay += " arrSecondary[" & intTempID & "][" &
rowTemp("SecondaryID") & "] = """ & _
rowTemp("SecondaryNumber") & " - " & rowTemp("Type") & """;" & vbCr
Next
strDisplay += "</script>" & vbCr

That loop right there uses a DataSet that was passed back. However, it's
only used once, and it's Forward only. It seems logical that a DataReader
should be used instead, saving the resources.

Is using a DataSEt the best solution for it? I was thinking of sending back an individual table, rather than create a DataSet. Wanted to throw it out
here to see if there was any better solution.

Nov 18 '05 #2
Kevin, Thanks for the reply. I know the DataReader would be a low
resource cost control, but I didn't think it was built to be passed
between logical tiers (business and Data).

I could see my Data Class using it to populate a DataTable,
but wouldn't it be better to just run a DataAdapert on that and fill my
DataTable, and throw that back to my Business Tier?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
its very bad pratice to return a DataReader from any layer. the creater of
the Reader should consume and release it. Otherwise you run into the
following problems:

1) lost resources if the reader is not deallocated correctly.
2) locking on the database because of delays in processing the reader. it
will hold database locks until its fully processed.
-- bruce (sqlwork.com)
"Ryan Ternier" <rt******************@icompasstech.com> wrote in message
news:eK**************@TK2MSFTNGP09.phx.gbl...
| Kevin, Thanks for the reply. I know the DataReader would be a low
| resource cost control, but I didn't think it was built to be passed
| between logical tiers (business and Data).
|
| I could see my Data Class using it to populate a DataTable,
| but wouldn't it be better to just run a DataAdapert on that and fill my
| DataTable, and throw that back to my Business Tier?
|
|
|
| *** Sent via Developersdex http://www.developersdex.com ***
| Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4
I don't understand this. I thought Microsoft Data Access Block return
datareaders, dataset, etc back to the caller from their helper classes.
Could you post a little of pseudo-code or code to explain your position
about passing data throught tiers
Thanks

"bruce barker" wrote:
its very bad pratice to return a DataReader from any layer. the creater of
the Reader should consume and release it. Otherwise you run into the
following problems:

1) lost resources if the reader is not deallocated correctly.
2) locking on the database because of delays in processing the reader. it
will hold database locks until its fully processed.
-- bruce (sqlwork.com)
"Ryan Ternier" <rt******************@icompasstech.com> wrote in message
news:eK**************@TK2MSFTNGP09.phx.gbl...
| Kevin, Thanks for the reply. I know the DataReader would be a low
| resource cost control, but I didn't think it was built to be passed
| between logical tiers (business and Data).
|
| I could see my Data Class using it to populate a DataTable,
| but wouldn't it be better to just run a DataAdapert on that and fill my
| DataTable, and throw that back to my Business Tier?
|
|
|
| *** Sent via Developersdex http://www.developersdex.com ***
| Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #5
Well, Ryan, I may get slammed for this by some, but my data tier can return
all 3 types of classes: DataSets, DataTables and DataReaders. I just make
sure I close the DataReaders and their connections when I use them. But
that's just me. My Uncle Chutney always said "Neither a follower nor a
lender be," and I kind of took it to heart. By that same token, I would have
to tell you to decide for yourself what the best architecture for your
application would be.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Ryan Ternier" <rt******************@icompasstech.com> wrote in message
news:eK**************@TK2MSFTNGP09.phx.gbl...
Kevin, Thanks for the reply. I know the DataReader would be a low
resource cost control, but I didn't think it was built to be passed
between logical tiers (business and Data).

I could see my Data Class using it to populate a DataTable,
but wouldn't it be better to just run a DataAdapert on that and fill my
DataTable, and throw that back to my Business Tier?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #6

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

Similar topics

0
by: William Ryan | last post by:
At the risk of sounding like a Big 5 consultant, "It depends". 1) Strongly typed datasets rock, they are faster than untyped, use intellisense... but your reason for wanting to use them is...
0
by: tstephan | last post by:
In the past we have used the classic nTier design with COM+, SQL Server and MFC. We are currently working on a new project with an opportunity to use .NET, ADO.NET, etc. One of the areas where I...
25
by: Stuart Hilditch | last post by:
Hi all, I am hoping that someone with some experience developing nTier apps can give me some advice here. I am writing an nTier web app that began with a Data Access Layer (DAL), Business...
1
by: Matt | last post by:
Hello, I'm working on a project in which i use Sql Server stored procedures to add and modify the records of our customers. This works fine, but when writing these stored procedures, i must use...
3
by: Rob Thomas | last post by:
Hi, I've been tasked to come up with a new architecture for a large application at one of my customer's sites. In the past, I have developed multi-tier applications whereby the business...
1
by: Dnx | last post by:
hi i'm a very beginner of visual studio .net 2003 and aspx/vb.net i have to create a project with an architecture ntier i understand the concept but in practical, i don't know where to begin... ...
16
by: Luqman | last post by:
Is it recommended to use datasets in ASP.Net 2.0 / VS.Net 2005 ? Best Regards, Luqman
0
by: Jon Vaughan | last post by:
Hello, I have an NTIER Model written in VB.NET, at the moment is running as a client / server. Pushing a pulling data from the client to the server is fine and is done via webservice calls. But...
0
by: Teo | last post by:
Hey guys!! I am looking at a user friendly tutorial on how to use Dataadapters, datatables and datasets to fill datagrids, etc. I am confused on using them a lot. Now I mostly use Datareaders and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.