Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Pass DataTable/DataSet to SQL Server - Possible?
Message
De
27/06/2005 17:56:57
 
 
À
27/06/2005 08:42:40
Keith Payne
Technical Marketing Solutions
Floride, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 1.1
OS:
Windows 2000 SP4
Database:
MS SQL Server
Divers
Thread ID:
01026601
Message ID:
01026878
Vues:
11
>>VS.NET 2003 - relative ADO.NET newbie
>>
>>A "checklist" form of an ASP.NET app I'm building pulls 81 rows out of SQL Server and DataBind()s it to a CheckBoxList. The user then checks/unchecks as many of the 81 options as required.
>>
>>Now I need to save the results. I'm going to DELETE the original 81 rows in SQL Server, INSERT the user's new choices and also copy the same 81 records out to a history table with a datetime stamp.
>>
>>It would be REALLY nice to be able to pass an ADO.NET DataTable or DataSet back to a SQL Server sproc in some fashion so I can do something like
INSERT INTO CheckListTable
>>  SELECT ... FROM < passed (cursor)? > ...
>>
>>... and then do something similar to the History table as well.
SQL Server BOL says an sproc can only specify a cursor parameter as an Output parameter, not an Input parameter.
>>
>>As an alternative I could loop through all 81 rows in the DataTable and send them back 1 at a time via standard parameters to an sproc but calling the sproc 81 times seems dumb - somehow feeding SQL Server all the rows in 1 chunk seems a lot more elegant, if possible.
>
>Al,
>
>A DataSet will be easier and more efficient than individual SqlCommands. However, if you want to max out the efficiency of the code, you should consider writing a stored procedure that accepts the foreign key and a concatenated string of the 81 booleans as parameters. Then split the string and perform the updates inside of a single transaction in the stored procedure.

I had a look at the SqlDataAdapter .InsertCommand etc. It looks like behind the scenes it would still pump out 81 individual sproc calls for my scenario. So, although the ADO.NET syntax might be simpler it wouldn't improve backend efficiency.

I finally implemented your idea of passing in a string - in my case containing fkey + Y/N pairs, delimited by commas. In the sproc I build a temp table, then easily update the checklist and history tables directly from that. Building the temp table row by row should avoid hitting the transaction log except for the final two multi-row INSERTs.

Everything's working great - thanks!
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform