不同部门的自动增量

时间:2016-02-10 09:03:15

标签: vb.net

所以这是我的插入文件的代码以及我需要自动增加代码但我不能使用id,因为它只有一个表中有这么多部门,例如

OP-BLDG-16-0001
LP-LAND-16-0001

codename.Text ="" &安培; codedepartment.Text& " - " &安培; code1.Text& " - " &安培; Now.Date.ToString(" yy")& " - " &安培; " 00" &安培; ""

这就是我做的第3个信息,我只需将其设置为自动增量

Try
dataB = "INSERT into assetpp ( [codes],[codedepartmentname]) VALUES ( '" & codename.Text & "','" & codedepartment.Text & "')"


            ConnDB()

            cmd = New OleDbCommand(dataB, conn)
            Dim i As Integer
            i = cmd.ExecuteNonQuery
            If i > 0 Then
                MsgBox("Add Succesfully", MsgBoxStyle.Information, "Confirmation")
                tableassetpp()

            Else
                MsgBox("Failed to add Data", MsgBoxStyle.Information, "Alert")

            End If

    Catch ex As Exception
        MsgBox(ex.Message)
    Finally
        cmd.Dispose()
        conn.Close()
    End Try

1 个答案:

答案 0 :(得分:0)

 Static cnt As Integer
        cnt = cnt + 1
        codename.Text = "" & codedepartment.Text & "-" & code1.Text & "-" & Now.Date.ToString("yy") & "-" & Format(cnt, "0000") & ""
相关问题