- Get link
- X
- Other Apps
Posted by
Real
- Get link
- X
- Other Apps
Some time we need to insert bunch of data directly from DataTable or DataSet to SQL Table, below is the code for Inserting data at once using Bulk copy Method:
// Bulk Copy to SQL Server
using (SqlBulkCopy bulkCopy =
new SqlBulkCopy(con))
{
bulkCopy.DestinationTableName = tableName;
foreach (DataColumn col in dt.Columns)
{
bulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName);
}
bulkCopy.WriteToServer(dt);
}
Comments
Yes it works fine, thank for the Code......
ReplyDeleteYou are welcome Amit. Keep visiting for more technical stuffs. I appreciate your valuable comments...
ReplyDelete