Re: Performance and Memory Usage Consideration about DataTable and Dat

Tech-Archive recommends: Fix windows errors by optimizing your registry



Ah, but in ASP net you can bind to a DataReader--just not in a Windows Forms
application.
Before you go off writing a bunch of code to handle rowsets or multiple
resultsets containing rowsets and populating arrays, consider that MS has
spent considerable time on performance in this area. ADO.NET can populate
multiple arrays for you in a single line of code: Use the DataAdapter Fill
method. It deals with a litany of issues as well--including connection
management (the bane of many an ASP app). You say a DataTable is not an
array? Ah, behind the scenes it's not really much more than an untyped
array. You can also load a DataTable with one line of code: the new Load
method works better than any manual DataTable populator I've seen.

Typically, more performance can be gained in the questions you ask (your
queries) than all of the fancy footwork dealing with the answer (the
rowsets) that's returned.

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------

"RobinS" <RobinS@xxxxxxxxxxxxxxx> wrote in message
news:CoqdnfBJp76T-p7bnZ2dnUVZ_sWdnZ2d@xxxxxxxxxxxxxx

You can't data bind to a DataReader; it only reads one record at a time.
It reads fast, but you have no retainability unless you store the rows
somewhere.

You can convert a datareader into a datatable, but why not just read it as
a DataTable.

Why are you so concerned about the memory taken up by the datatable? Once
it goes out of scope, the GC will know it can be cleared. If it has a
Dispose method, you can invoke it and the GC might dispose of it sooner.
I can't believe an array of the same information would take up a lot less
information. After all a data table is an array of DataRows.

That's my two cents' worth.
Robin S.
-------------------------
"Samuel" <programmer@xxxxxxxxxxxxx> wrote in message
news:73E17D3D-7AD0-4E89-9FA5-8E7EF5C8478D@xxxxxxxxxxxxxxxx
Hi,

How do I free up the memory taken up by the .NET datatable and dataset
after
I finished working with them? How do I HELP the GC to do its job sooner
to
release memory taken up by DataTable/DataSet?

I am worried about memory usage. Should I be using DataReader
exclusively?
But complex databinding is going to cause problem to me because it is
going
to keep the connection open for longer than necessary.

Would it help if I create an arraylist of DbDataRecord from DataReader
instead?

If reader.HasRows Then
For Each rec As System.Data.Common.DbDataRecord In reader
arr.Add(rec)
Next
End If

I am guessing that arraylist takes up less memory than a DataTable. Am I
correct? Or is there a way for me to check how much memory each takes up
(datatable v.s. Arraylist of DbDataRecord)?

Then, how do I use this technique to construct more than one arraylist
when
the datareader returns more than one result set? I can only get the first
resultset and i don't know why. It seems that the reader is closed
automatically when I use this technique.

Another question I have is about DataTable's DataTableReader. What's the
point to use a DataTableReader? Does it make databinding faster than
binding
to Datatable itself? I am sure this would not take less memory so why?

Thanks for any advice you can provide!




.



Relevant Pages

  • Re: Performance and Memory Usage Consideration about DataTable and Dat
    ... You can't data bind to a DataReader; it only reads one record at a time. ... How do I free up the memory taken up by the .NET datatable and dataset ... Another question I have is about DataTable's DataTableReader. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Performance and Memory Usage Consideration about DataTable and
    ... Yes, you can bind controls to datareader, ... Have in mind DataReader is used internally in DbDataAdapter.Fill method ... How do I free up the memory taken up by the .NET datatable and dataset ... Another question I have is about DataTable's DataTableReader. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Performance and Memory Usage Consideration about DataTable and Dat
    ... How do I free up the memory taken up by the .NET datatable and dataset after ... Would it help if I create an arraylist of DbDataRecord from DataReader ... automatically when I use this technique. ... Another question I have is about DataTable's DataTableReader. ...
    (microsoft.public.dotnet.framework.adonet)
  • RE: DataReader to DataTable...
    ... Microsoft uses a DataReader to fill their own DataSets (or rather DataTables ... you have a Load() method to make it easier ... Microsoft's own documenation shows the new DataTableReader being used rather ... For the SqlDataReader, my next line of attack would be setting it up as its ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: DataReader to DataTable...
    ... Microsoft uses a DataReader to fill their own DataSets (or rather DataTables ... you have a Load() method to make it easier ... Microsoft's own documenation shows the new DataTableReader being used rather ... For the SqlDataReader, my next line of attack would be setting it up as its ...
    (microsoft.public.dotnet.framework.aspnet)