有多个数据操作,而且是循环的,怎么用事务来做回滚呢
SqlConnection Connection = new SqlConnection(Exam.Global.m_strSqlString);
Connection.Open();
SqlTransaction Tran = Connection.BeginTransaction();
try
{
for (; i < studentId.Length; i++)
{
sDB.YunSqlExecuteNonQuery( "CreatePaper ", parameters, Tran);
UpdateSubjectDegree(subjectIds, Tran);
}
i = 0;
for (; i < studentId.Length; i++)
{
sDB.YunSqlExecuteNonQuery( "update_applyExam2 ", parameters, Tran);
}
sDB.ExcuteSqlCommand(sql, Tran);
BackupPolicy(policy_id, ex_auditing_id, Tran);
Tran.Commit();
Response.Redirect( "Exams.aspx?kind= " + kind);
}
catch (Exception exp)
{
Tran.Rollback();
Response.Write(exp.Message);