zoukankan      html  css  js  c++  java
  • sqlserver ADO.net 查询数据库加锁,事务提交

    //逻辑:查询表最大单号,然后锁表(TABLOKX) ,然后执行事务
    using
    (SqlConnection conn = EFContext.Database.Connection as SqlConnection) { System.Data.SqlClient.SqlCommand cm = new System.Data.SqlClient.SqlCommand(); cm.Connection = conn; conn.Open(); System.Data.SqlClient.SqlTransaction trans = conn.BeginTransaction(); try { cm.Transaction = trans; //获取写进ERP的单据号 cm.CommandText = "select max(MasterId) from TBusTran WITH (TABLOCKX)"; SqlDataReader dr = cm.ExecuteReader(); while (dr.Read()) { int n = 0; while (n < dr.FieldCount) //.FieldCount获取当前行的列数 { newMasterId = GetSerialNumber_Tran(dr[n].ToString(), "P"); n++; } } dr.Close(); string sql8 = string.Format("insert into TBusQualityProblem_FlowView([FlowNo],[OperatName],[OperatDate],[OperatType],[Status])values('{0}','{1}','{2}','{3}','{4}')", MasterId, Opr_LoginId, DatetimeNow, OperatType, Status); cm.CommandText = sql8; cm.ExecuteNonQuery(); trans.Commit(); } catch (Exception) { trans.Rollback(); result.Success = false; result.Message = "操作异常!"; throw; } finally { conn.Close(); trans.Dispose(); conn.Dispose(); } }
  • 相关阅读:
    动态水母
    jquery封装的方法
    近千部最新英文读物(word 格式)及下载阅读方法
    best tanks
    System Analysic utility tools
    高级商务英语(BEC)阅读题应试指南
    “牛”人是怎样学习的
    领悟
    BEC高级商务英语考试应试技巧指南
    因特网上的英语学习资源
  • 原文地址:https://www.cnblogs.com/zoumin123/p/9142242.html
Copyright © 2011-2022 走看看