C#回滚事务

string  str="server=.;initial catalog=mytest;integrated security=true;" 

using( SqlConnection conn = new SqlConnection(str))

{
 using(SqlCommand command = conn.CreateCommand())

{

conn.Open();
SqlTransaction transaction =conn.BeginTransaction();
command.Transaction = transaction;
try
{
               command.CommandText = "insert into company values('AA','AAAA','true','null')";
                command.ExecuteNonQuery();
                 transaction.Commit();
}
catch
{

                transaction.Rollback();

}

}

}


展开阅读全文

没有更多推荐了,返回首页