#region 对表数据删除事务回滚
/// <summary>
/// 对表数据删除事务回滚
/// </summary>
/// <param name="id">待传入表1,2的通用编号</param>
/// <param name="tableName1">待传入表1</param>
/// <param name="tableName2">待传入表2</param>
/// <returns></returns>
public bool DelRollBack(int id, string tableName1, string tableName2)
{
OpenDB();
SqlTransaction sqlTran = Conn.BeginTransaction();//开始事务
SqlCommand cmd = new SqlCommand();
cmd.Connection = Conn;//获取数据连接
cmd.Transaction = sqlTran;//在执行sql语句时等待提交和rollback
try
{
string sqlStr1 = "delete " + tableName1 + " where FTCPParentId=" + id + "";
cmd.CommandText = sqlStr1;
cmd.ExecuteNonQuery();
string sqlStr2 = "delete " + tableName2 + " where FCaseChildId=" + id + "";
cmd.CommandText = sqlStr2;
cmd.ExecuteNonQuery();
sqlTran.Commit();
return true;
}
catch
{
sqlTran.Rollback();
return false;
}
}
#endregion