Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Updating, Inserting into a table with a lot of columns
Message
De
30/09/2010 13:22:06
 
 
À
29/09/2010 18:36:25
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Versions des environnements
Environment:
C# 4.0
Divers
Thread ID:
01483278
Message ID:
01483378
Vues:
52
Thanks for looking at my blog, Bill!

Yes, Naomi is correct about the parameters. If this is a SQL Server database, then you'd want to be using the SqlDataAdapter and named parameters and it'll all work fine.

If it's not a SQL Server database and you have to use the OleDbDataAdapter and positional parameters, this won't work since the parameters are positional. But, in that situation you can use the OleDbCommandBuilder.DeriveParameters() method (that method exists for SqlCommandBuilder also). There are two downsides to this method:

1) there's an extra round-trip to the database so it can figure out the parameters for you and
2) you still need to supply the value, but that may be able to be done in a loop through the DataTable's columns, similar to the SetAllParameters() method in my blog post.

~~Bonnie



>In an app I'm developing, I'm using stored procedures to update and create new records for a table.
>There are lots and lots of columns in this table and it will grow as the app matures.
>I'm creating the command to call to the stored procedure and adding the parameters, one by one.
>That's a LOT of typing.
>
>Looking at Bonnie's blog, I found some code that will generate the parameters and values for me.
>Will that work if the generated parameters are not in the same sequence as they are declared in the stored procedure?
>
>Any other ideas to cut down on the typing?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform