Groups | Blog | Home
all groups > dotnet datatools > september 2004 >

dotnet datatools : Which is faster



Todd Lu
9/16/2004 3:43:26 PM
I am using APS.NET 2003 with SQL 2000.

I have a datagrid that I want to save after all the changes are place in it.

First of all what is the most efficient way to update multiple rows of
records into sql from a datagrid?

Currently I am looping through my datagrid and calling a stored procedure to
update the records for each row but this just seems so brute force, is there
an elegant way of doing this?

Another question in line with this is that I also have an array with 24
columns and 40 rows. Is there a batch method to import this information
into a sql table?

Thanks,

Todd


Jonathan Levine
9/16/2004 6:31:06 PM
Todd,

[quoted text, click to view]

Are all the rows updated with the same information? Or could there be
different information for each row?

[quoted text, click to view]

This is in a .NET array? Or in a file? How often do you need to import the
info? Just once? Every day? Every minute?

Regards,
Jonathan
Todd Lu
9/17/2004 7:27:23 AM
Jonathan,
Thanks for the response,
1. Datagrid
Each row could have the same information but most likely will not. The
information that are changing on the datagrid rows are 4 check boxes the
user can choose any combination of the check boxes for multiple rows before
they need to save so that is why I would like to save only once for all the
rows.

2. Array
The array that I am using is a older vb6 arrary that I ported over to my
ASP.NET project.
Private JResultArray(41, 25, 8) As Double

I will need to import the information everytime a calculation button is
clicked.

Thanks again,

Todd

[quoted text, click to view]

Jonathan Levine
9/20/2004 5:23:05 PM
Todd,

[quoted text, click to view]

I think you're stuck here. You could set up a DataSet/DataAdapter pair,
modify each row in the DataSet, then call DataAdapter.Update() with the
modified DataSet; however, because of limitations of SQL, the DataAdapter is
going to make an Update for each modified row. This is a limitation of SQL
and is hard to work around (you can only specify one set of new values in an
UPDATE).

[quoted text, click to view]

The easiest way to do this is going to again be with a DataAdapter/DataSet
pair. Depending on the underlying database, the DataAdapter might be able to
optimize this (some flavors of SQL support inserting multiple rows in a
single INSERT).

In general, unless you have a very slow storage device, or you have
thousands of simultaneous users, I think you are unlikely to see any
performance difference between one UPDATE and multiple UPDATEs or one INSERT
and multiple INSERTs.

AddThis Social Bookmark Button