private static void SqlFastInsert(DbConnection dbConnection, DbTransaction trans, DataTable dt) { using (SqlBulkCopy sqlbulkcopy = new SqlBulkCopy(dbConnection as SqlConnection, SqlBulkCopyOptions.Default, trans as SqlTransaction)) { sqlbulkcopy.DestinationTableName = dt.TableName; for (int i = 0; i < dt.Columns.Count; i++) { sqlbulkcopy.ColumnMappings.Add(dt.Columns[i].ColumnName, dt.Columns[i].ColumnName); } sqlbulkcopy.BatchSize = 10000; sqlbulkcopy.WriteToServer(dt); } } private static void MySqlFastInsert(DbConnection dbConnection, DbTransaction trans, DataTable dt) { MySqlConnector.MySqlBulkCopy mySqlbulkcopy = new MySqlConnector.MySqlBulkCopy(dbConnection as MySqlConnector.MySqlConnection, trans as MySqlConnector.MySqlTransaction); { mySqlbulkcopy.DestinationTableName = dt.TableName; for (int i = 0; i < dt.Columns.Count; i++) { mySqlbulkcopy.ColumnMappings.Add(new MySqlConnector.MySqlBulkCopyColumnMapping(i, dt.Columns[i].ColumnName)); } mySqlbulkcopy.WriteToServer(dt); } } /// <summary> /// Oracle快速写入 /// </summary> /// <param name="dbConnection"></param> /// <param name="trans"></param> /// <param name="dt"></param> private static void OracelFastInsert(DbConnection dbConnection, DbTransaction trans, DataTable dt) { Oracle.ManagedDataAccess.Client.OracleBulkCopy oraclebulkcopy = new Oracle.ManagedDataAccess.Client.OracleBulkCopy(dbConnection as Oracle.ManagedDataAccess.Client.OracleConnection, Oracle.ManagedDataAccess.Client.OracleBulkCopyOptions.Default); { oraclebulkcopy.DestinationTableName = dt.TableName; for (int i = 0; i < dt.Columns.Count; i++) { oraclebulkcopy.ColumnMappings.Add(dt.Columns[i].ColumnName, dt.Columns[i].ColumnName); } oraclebulkcopy.BatchSize = 10000; oraclebulkcopy.WriteToServer(dt); } }
标签:dbConnection,ColumnName,C#,数据库,sqlbulkcopy,大批量,dt,MySqlConnector,Columns From: https://www.cnblogs.com/liao-long/p/16710466.html