nTier question regarding DataSets and DataReaders

R

Ryan Ternier

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.
 
K

Kevin Spencer

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.
 
R

Ryan Ternier

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?
 
B

bruce barker

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)


| 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?
|
|
|
|
| Don't just participate in USENET...get rewarded for it!
 
G

Guest

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
 
K

Kevin Spencer

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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top