using(SqlConnection conn = new SqlConnection(str))
{
conn.Open(); using (System.Data.SqlClient.SqlBulkCopy sqlBC = new System.Data.SqlClient.SqlBulkCopy(conn)) { sqlBC.BatchSize = 10000;// 每次提交的数量级
sqlBC.BulkCopyTimeout = 60; sqlBC.DestinationTableName = "dbo.Table1";//需要插入的表名 sqlBC.ColumnMappings.Add("ColumnName1OfDt", "Field1OfTable1");
sqlBC.ColumnMappings.Add("ColumnName2OfDt", "Field2OfTable1");
sqlBC.WriteToServer(dt);//自定义的 datatable } conn.Dispose();
}