以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]这样写 事务可以生效么?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=52404)

--  作者:jiskin
--  发布时间:2014/6/15 14:27:00
--  [求助]这样写 事务可以生效么?
改了下编号生成 这样不知道可以不可以?请帮忙看看


        Try
            Connections("SZATVERPDB").BeginTransaction()
            Dim Key As Integer
            Dim num As String
            cmd.commandText = "Select Count(*) From 编号 Where 前缀 = \'" & lbh & "\'and 表名 = \'物料库存\'"
            If cmd.ExecuteScalar = 0 Then
                cmd.commandtext = "Insert Into 编号 (表名,前缀,序列) Values(\'物料库存\',\'" & lbh & "\',1)"
                cmd.ExecuteNonQuery
            End If
            cmd.commandText = "Select 序列 From 编号 Where 前缀 = \'" & lbh & "\'and 表名 = \'物料库存\'"
            Key = cmd.ExecuteScalar()
            cmd.commandText = "Update 编号 Set 序列 = " & (Key + 1) & " Where 序列 = " & Key & " And 前缀 = \'" & lbh & "\'and 表名 = \'物料库存\'"
            cmd.ExecuteNonQuery()
            num = lbh & Format(Key,"0000")
            cmd.CommandText = "Insert Into ……
            cmd.ExecuteNonQuery()
            cmd.CommandText = "Insert Into ……
            cmd.ExecuteNonQuery()
            Connections("SZATVERPDB").Commit
        Catch ex As Exception \'如果出错
            Connections("SZATVERPDB").Rollback() 
            messagebox.show("新增失败!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error)
        End Try

--  作者:有点甜
--  发布时间:2014/6/15 14:30:00
--  
 有效。
--  作者:jiskin
--  发布时间:2014/6/15 14:33:00
--  
以下是引用有点甜在2014-6-15 14:30:00的发言:
 有效。

 

多谢甜总,甜总真是日理万机啊