改了下编号生成 这样不知道可以不可以?请帮忙看看
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