which is a better use of the data

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Given the following situation which is better, should the data be read using
a datareader then put into a grid for inline editing, etc. Or should it be
placed into a Datatable then datagrid for the same activity?
web app., maybe 50 users at once, record size maybe 100-250.
I've read that using a connected dataReader to get and populate, then close
the connection is light and fast. And that datatables are disconnected and
memory resident. There must be a re-use advantage to a datatable. But both
are placed into a datagrid for the same inline editing. I would think that if
you need to update a larger set of data at once then datatable. What are the
advantages and disadvanatges of both?

thanx.
 
It all depend on how the data is used. You did goog thing to connec to
database to retrieve/update data, and then disconnect it. But you need to
consider how the data is used in your business logic. If the data is only
for browsing, and not State is needed to maintain (typically by using
Session object), then use DataReader to get data and drop it onto a DataGrid
is fine.But if you want user to do something on the data through the
DataGrid (edit/delete/select), the DataGrid has to be posted back and
re-bind to the data. Do you want to retrieve data from database each time
when the datagrid is posted back? Generally, in case like this, it is better
to use DataSet/DataTable retrieved from database when the page is called the
first time, and bind it to DataGrid, and save the DataSet/DataTable in
Session. When DataGrid gets posted back, the data changed by user will
applies to DataSet/DataTable stored in Session, and update to database only
it is necessary. Again, it is depends on how the data is used, and how much
the data amount is...
 
Isn't disconnecting it by using a datatable good for changing more than one
record. With a DataReader you can dump to the datagrid and when you perform
an inline edit just open, update/insert, then close. The Dataset/DataTable is
also held in memory, so the quesiotn I would ask is which impacts the app
more, memory or open and closing a connection?

The data is simple, maybe 10-20 fields, 100 rows.

In a datatable aren't you still calling an Update, thus, is this better
given the above information better than datareader?

thanx.
 
First question, how do you propse to dump the data into the datagrid
using a data reader? You cant databind it by setting the data source
property of the datagrid, since the data reader doesnt implement either
IList or IListSource.

NuTcAsE
 
Not sure I understand your question:

By simply:
datagrid.DataSource = cmdSelect.ExecuteReader()
datagrid.DataBind()
 
Sorry, stupid q. I assumed you were talking about winforms. It
completely sliped my mind that a ASP.Net datagird can bind to a data
reader or anything that implements IEmumerable. Sorry :)

Anywas my suggestion if your looking for higher response time for your
clients go with dataset. Your clients then can make all thier changes
at once then update. If performance in terms of memory is an issue, id
first take a look at data sets and do a benchmark on how much memory
does your app consume on peak load. Then test with a datareader. The
reason i wouldnt use a data reader and use concurrent updates/inserts
after every edit is that imagine 50 users adding or removing a row at
every 2 sec intervals. Thats 50 connections open, issue command and the
close connection. OTH when using data sets the trafic to the database
is saved by reducing the no of roundtrips the client has to perform. If
memory is really an issue and you are ready to sacrafice your apps
responsivenes... i guess data reader. But the datareader would be a
last option.

NuTcAsE
 
thanx, I'm curoius that if the user is doing inline editing only (one record
at a time) then I wonder what would be best. If you open and fill drid using
datareader then close connection then it's free until the instance of an
update, that would use another connection.
If a dataset is read and fills a grid then that's one connection moment.
Then when it saves the data back ins't that another? so isn't it the same for
a one record update?

thanx.
 
Also, what happenes if someone creates a datatable, thus snapshoting the data
by disconnecting it, then another suer does the same. Then one user makes
several changes to the data, as does the other user, won't one user override
the other's data upon update? how do you protect that?
 
See my earlier posting "concurrency help".

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
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.
__________________________________
 
Back
Top