日期:2014-05-18 浏览次数:21070 次
using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; SqlTransaction tx = conn.BeginTransaction(IsolationLevel.ReadUncommitted); cmd.Transaction = tx; SqlBulkCopy sbc = new SqlBulkCopy(conn, SqlBulkCopyOptions.Default, tx); string sql = string.Empty; for (int n = 0; n < listSql.Count; n++) { string strsql = listSql[n]; if (strsql.Trim().Length > 1) { cmd.CommandText = strsql; sql = strsql; cmd.ExecuteNonQuery(); } } sbc.DestinationTableName = tableName; sbc.WriteToServer(dt); tx.Commit(); }