Thursday, May 31, 2012

Bulk Insert Into SQL Table using BulkCopy from DataTable

In the previous post ADD, Delete and Update in datatable was posted. Now continuing the previous post for Bulk Insertion from DataTable you can write the following code in a button click to insert into SQL datatable as shown below.

This is a method as shown

private void Bulkinsert()
        using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings[
            using (SqlBulkCopy copy = new SqlBulkCopy(cn))
                copy.ColumnMappings.Add(1, 1);
                copy.ColumnMappings.Add(2, 2);
                copy.DestinationTableName = "TableName";

No comments:

Post a Comment