SQL Bulk Copy Class using C#

In this article we are going to see about the SQL Bulk Copy class which provides easiest way to save data in table. Using the code in the article will make easy to save the records into database table easily.

SQL Bulk Copy:

The simplest way to insert data into the table is to use SQL Bulk Copy class. NET Framework 2.0 contains a class in ADO.NET "System.Data.SqlClient". Need to add the below namespace in order to use this SQL Bulk copy class.


SqlBulkCopy bulkcopy = new SqlBulkCopy(ConfigurationManager.ConnectionStrings["DBConn"].ToString());
bulkcopy.DestinationTableName = "[AN_TBL_Authorized]";

The above code inserts the values to the table.

1) Create instance for bulk copy class and give the connection string of the database.
2) Give the destination table name in which you want to insert data.
3) Here pass a data table to writetoserver which inserts the data.
4) Following this to work the pass the value to data table in the order which is in the corresponding table. Because based on that only the data will be inserted. Passing the values in data table wrongly, might save the values wrongly in table.


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: