Search code examples
c#sqlbulkinsertsql-server-2008-express

Adding bulk values to SQL Server database with c# winform


I'm using SQL Server 2008 Express.

What is the best way to import bulk values into the database from a C# app?

Right now I have some textboxes and I can import data without any problem. And I would like to import not only one row ,by "click to a button" but 3 or 4.

Please help me!


Solution

  • For 3 or 4 rows, I would suggest setting up a SqlCommand with a parameterized insert statement, creating and binding parameters for the inserted columns, and then calling ExecuteNonQuery. You can retain the same SqlCommand and SqlParameters objects, reassign new values to the SqlParameters, and then do the next ExecuteNonQuery for the next row.

    However, if you are doing a much larger insert (as in 100k rows at a time), you should look at using SqlBulkCopy - this allows for high performance bulk inserts (and only inserts) into a table.