Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Updating a Database Questions
Message
From
15/09/2004 11:02:10
 
 
To
15/09/2004 10:31:18
Jim Rieck
Quicken Loans/Rock Financial/Title Sourc
Livonia, Michigan, United States
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00942400
Message ID:
00942418
Views:
15
Jim,

I do a similar process for updating my database with Stored Procs ... however, there are a couple of other options you can use rather than hard-coding the adding of every parameter to your command (not really a very elegant solution, since you have to revisit this every time your schema or Stored Proc changes).

1) I have a method in my Base DataAccess method that I call SetBasicParameters(). Basically what it does is go through every column in a DataTable and add a parameter for that column if the value is not DBNull. I call this method and if a DataTable doesn't totally correspond to it's backend counterpart, I can remove a few parameters before running the .ExecuteNonQuery().

2) I also have a method called SetNamedParameters(). This one utilizes the SqlCommandBuilder.DeriveParameters() method to set up the parameters. I use this method if the StoredProc I'm going to use has way different parameters than the DataTable. It takes a little more time to use this one however, as the CommandBuilder makes an extra trip to Sql Server to find your StoredProc in order to figure out what parameters you need.

Anyway, those are your two options. Use one or the other, or a combination of both (as I do).

HTH,
~~Bonnie


>All,
>
> In the world of Microsoft programming there has always been more than one way to do something. My question pertains to what is the right or best way to get data from a dataset into the database when using a data adapter. The way I've done it now is the insert, update or delete command on the data adapter is set to the proper stored procedure in the database. Most of the stored procedures have parameters. In my code I update each of the parameters on the command and call the executenonquery method on the command. Hence the database is then updated, inserted or deleted. The problem gets to be that if there are a lot of parameters being passed to the stored procedure there is 1 line of code for each 1. Is there another or better method of updating a database?
>
>Any thoughts or other information would be greatly appreciated.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform