您可以尝试
SqlBulkCopy将数据表插入数据库表
像这样
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnection, SqlBulkCopyOptions.KeepIdentity)){ bulkCopy.DestinationTableName = DestTableName; string[] DtColumnName = YourDataTableColumns; foreach (string dbcol in DbColumnName)//To map Column of Datatable to that of Database tabele { foreach (string dtcol in DtColumnName) { if (dbcol.ToLower() == dtcol.ToLower()) { SqlBulkCopyColumnMapping mapID = new SqlBulkCopyColumnMapping(dtcol, dbcol); bulkCopy.ColumnMappings.Add(mapID); break; } } } bulkCopy.WriteToServer(YourDataTableName.CreateDataReader()); bulkCopy.Close();}
有关更多信息,请参见http://msdn.microsoft.com/zh-
cn/library/system.data.sqlclient.sqlbulkcopy.aspx
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)