多表删除的一个例子:
1 public int DeleteContractData(long ContractID) 2 { 3 string delContractInfo = @"UPDATE ContractInfo SET DelFlag=1 WHERE ContractID=@ContractID"; 4 5 //数据库连接属性 引用using System.Data.SqlClient; 6 using (SqlConnection IDbCon = new SqlConnection(ConfigureHelp.Connection)) 7 { 8 //数据库连接 9 IDbCon.Open(); 10 //开启事务。需引用using System.Data; 11 IDbTransaction _tran = IDbCon.BeginTransaction(); 12 try 13 { 14 //在参数后面放入 事务参数 15 int delCI = IDbCon.Execute(delContractInfo, new { @ContractID = ContractID }, _tran); 16 if (delCI > 0) 17 { 18 //事务提交 19 _tran.Commit(); 20 return 1; 21 } 22 else 23 { 24 //操作失败、事务回滚 25 _tran.Rollback(); 26 return 0; 27 } 28 } 29 catch (Exception ex) 30 { 31 _tran.Rollback(); 32 UtilityHelp.WriteLog(ex, ex.ToString()); 33 return -1; 34 } 35 } 36 }