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.