解锁表无法运行

时间:2016-11-29 08:04:49

标签: sql vb.net locking unlock

我有这个代码通过select max生成自动编号,我使用锁定表。 我的问题是为什么解锁表在锁定表后无法运行?

Sub locking()
        Dim nomortrans As Integer
        SQL = "lock tables tblpos_trans_nomor write, tblpos_trans_nomor as tn2 read"
        Proses.ExecuteNonQuery(SQL)
        SQL = "insert into tblpos_trans_nomor (s_nomor_trans) select MAX(s_nomor_trans)+1 from tblpos_trans_nomor as tn2"
        Proses.ExecuteNonQuery(SQL)
        TblPayment = Proses.ExecuteQuery("select MAX(s_nomor_trans) from tblpos_trans_nomor as tn2")
        nomortrans = TblPayment.Rows(0).Item(0)
        frm_pos.LblNomorTransaksi.Text = nomortrans
        frm_pos3.LblNomorTransaksi.Text = nomortrans
        SQL = "unlock tables"
        Proses.ExecuteNonQuery(SQL)
End Sub

如果我在运行时编辑没有问题,但是我无法解析值select max,

Sub locking()
        Dim nomortrans As Integer
        SQL = "lock tables tblpos_trans_nomor write, tblpos_trans_nomor as tn2 read"
        Proses.ExecuteNonQuery(SQL)
        SQL = "insert into tblpos_trans_nomor (s_nomor_trans) select MAX(s_nomor_trans)+1 from tblpos_trans_nomor as tn2"
        Proses.ExecuteNonQuery(SQL)
        SQL = "unlock tables"
        Proses.ExecuteNonQuery(SQL)
End Sub

0 个答案:

没有答案