//使用事务来处理多条数据,如果不成功则回滚

public void getCheckListSubmit()
{
string _conStr = "................";//连接字符串
OdbcConnection _odbcCon = new OdbcConnection(_conStr);
_odbcCon.Open();

OdbcTransaction trans = _odbcCon.BeginTransaction(IsolationLevel.ReadCommitted);
OdbcCommand cmd = new OdbcCommand();
cmd.Connection = trans.Connection;
cmd.Transaction = trans;

string sqlStr = "";
try
{
sqlStr = ".................";

cmd.CommandText = sqlStr;
cmd.ExecuteNonQuery();

sqlStr2 = ".................";
cmd.CommandText = sqlStr2;
cmd.ExecuteNonQuery();

}
catch
{
trans.Rollback();
hidsysMsg.Value = "Insert Failed";
_odbcCon.Close();
return;
}
trans.Commit();
hidsysMsg.Value = "Insert Succeeded";
_odbcCon.Close();

}

相关文章:

  • 2022-12-23
  • 2021-12-26
  • 2022-02-11
  • 2021-09-13
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
猜你喜欢
  • 2021-06-08
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案