Inserting SQLSever rows
-
What is the easiest what to load 4000 rows into a SQLSever db from a C# program? The C# rows are in an ArrayList. And the "scheme" is very simple [string, date, decimal, decimal, integer]. I’m looping threw the array, right now, and doing an insert for each row but I’m wondering if there is some way I can do this in bulk? I think BCP would be overkill in this case, so, I'm just wondering if there is something in ADO.NET that might handle a "large" number if inserts.
-
What is the easiest what to load 4000 rows into a SQLSever db from a C# program? The C# rows are in an ArrayList. And the "scheme" is very simple [string, date, decimal, decimal, integer]. I’m looping threw the array, right now, and doing an insert for each row but I’m wondering if there is some way I can do this in bulk? I think BCP would be overkill in this case, so, I'm just wondering if there is something in ADO.NET that might handle a "large" number if inserts.
BCP would definitely be the best way. You could write out the file and execute BCP on it. You could also use parameters inserts. Construct your
SqlCommand
with parameters for the fields. When enumerating over yourArrayList
, set theSqlParameter.Value
for each field and callSqlCommand.ExecuteNonQuery
. BCP will probably be faster, though.Microsoft MVP, Visual C# My Articles
-
What is the easiest what to load 4000 rows into a SQLSever db from a C# program? The C# rows are in an ArrayList. And the "scheme" is very simple [string, date, decimal, decimal, integer]. I’m looping threw the array, right now, and doing an insert for each row but I’m wondering if there is some way I can do this in bulk? I think BCP would be overkill in this case, so, I'm just wondering if there is something in ADO.NET that might handle a "large" number if inserts.
You can also just batch the insert statements together and execute them all at once, or in smaller batches of 10 or so. Just seperate the statements with ;
If you don't kill me you will only make me stronger That and a cup of coffee will get you 2 cups of coffee