C# 事务控制循环插入数据 同一sql语句

mac2022-06-30  17

 View Code public int ExecuteSql(List < string > listsql) { OleDbCommand command = null ; try { Open(); command.Connection = conn; command.Transaction = conn.BeginTransaction(); int i = 0 ; foreach ( string sql in listsql) { command.CommandText = sql; i += command.ExecuteNonQuery(); } command.Transaction.Commit(); return i; } catch (OleDbException e) { command.Transaction.Rollback(); foreach ( string sql in listsql) log.Error(sql, e); } return 0 ; }

转载于:https://www.cnblogs.com/Mr0909/archive/2011/05/13/2045780.html

最新回复(0)