2 回答
TA贡献1772条经验 获得超5个赞
using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
{
conn.Open();
SqlTransaction tran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = tran;
cmd.Connection = conn;
try
{
//事务操作开始
string sql = string.Format("insert..")
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
//事务操作结束
tran.Commit();
}
catch (Exception ex)
{
tran.Rollback();
throw ex;
}
finally
{
conn.Close();
}
}
sqlserver 事务的程序调用。是不是你要的啊?
- 2 回答
- 0 关注
- 451 浏览
添加回答
举报