//启动一个事物 SqlTransaction tran= sqlConnect.BeginTransaction(); //为事务创建命令 sqlConnect.Transaction = tran; try { foreach (DataRow row in table.Rows) { sqlCmm.Parameters[0].Value = row["id"]; sqlCmm.Parameters[1].Value=row["name"]; sqlCmm.Parameters[2].Value=row["nums"]; sqlCmm.ExecuteNonQuery(); } //提交事务 tran.Commit(); } catch(Exception ex) { Response.Write(ex.Message); //回滚事务 tran.Rollback(); }