事务提交和回滚 [英] Transaction commit and rollback
问题描述
大家好,
我需要添加提交"和回滚"事件,这对于我的下面的编码是必需的.
请根据需要编辑我的代码,而只需付出最小的努力.
public int delete_shareholder(int investors_id)
{
SqlConnection conn =新的SqlConnection(conn_str); ;
cmd.CommandType = CommandType.StoredProcedure;
try
cmd.Parameters.AddWithValue(``@ shareholder_id''``/>返回cmd.ExecuteNonQuery();
}
catch
throw { > cmd.Dispose();
conn.Close();
conn.Dispose();
}
Hi All,
I need to add "Commit" and "Rollback" events as necessary for my below coding.
Please edit my code as necessary with minimum effort to change.
public int delete_shareholder(int shareholder_id)
{
SqlConnection conn = new SqlConnection(conn_str);
conn.Open();
SqlCommand cmd = new SqlCommand("sp_update_shareholder", conn);
cmd.CommandType = CommandType.StoredProcedure;
try
{
cmd.Parameters.AddWithValue("@shareholder_id", shareholder_id);
return cmd.ExecuteNonQuery();
}
catch
{
throw;
}
finally
{
cmd.Dispose();
conn.Close();
conn.Dispose();
}
}
推荐答案
"请根据需要编辑我的代码,更改."
Cheeky ....
使用System.Transactions命名空间中的类.
http://msdn.microsoft.com/en-us/library/ms172152.aspx
一点也不难....
Hi,
"Please edit my code as necessary with minimum effort to change."
Cheeky....
Use the classes in the System.Transactions namespace.
http://msdn.microsoft.com/en-us/library/ms172152.aspx
Not difficult at all....
这篇关于事务提交和回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!