怎样提交事务?
在SqlConnection对象中,有开始事务的操作BeginTransaction(),还有没有提交事务的操作?如果没有,怎样提交事务?
------解决方案-------------------- System.Data.SqlClient.SqlConnection conn;
System.Data.SqlClient.SqlTransaction tran = conn.BeginTransaction();
try
{
tran.Commit();
}
catch
{
tran.Rollback();
}
------解决方案--------------------SqlTransaction trans = null; //定义事务
SqlConnection con = null;
con = new SqlConnection(constring);
con.Open();
trans = con.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.Transaction = trans;
trans.Commit(); //提交事务
trans.Rollback();//回滚事务