标签:
private void SqlBulkCopyByDataTable(string connectionString,string TableName,DataTable dt) { using (SqlConnection sqlconn = new SqlConnection("connectionstring")) { using (SqlBulkCopy sqlbulkcopy = new SqlBulkCopy("connectionstring",SqlBulkCopyOptions.UseInternalTransaction)) { try { sqlbulkcopy.DestinationTableName = TableName; for(int i = 0;i<dt.Columns.Count;i++) { sqlbulkcopy.ColumnMappings.Add(dt.Columns[i].ColumnName, dt.Columns[i].ColumnName);//第一个参数数据源中源列名称,列二个参数目标表列名 } sqlbulkcopy.WriteToServer(dt); } catch(System.Exception ex) { throw ex; } } } }
标签:
原文地址:http://www.cnblogs.com/liumengchen-boke/p/5725888.html