单击保存按钮时,询问自动编号不会增加

时间:2015-02-03 01:33:16

标签: vb.net

我的案子需要帮助。

我有一个id_staff自动编号的程序,当表格加载时,自动编号正常工作但是当点击保存按钮时,自动编号不起作用,我必须关闭表格并重新加载表格才能生成它发生了。

请帮帮我..

以下是我的代码..任何建议都将受到高度赞赏

Sub id_barang()
    Call koneksi()
    cmd = New OleDbCommand("Select * from tb_lokasi order by id_barang desc", conn)
    dr = cmd.ExecuteReader
    dr.Read()
    If Not dr.HasRows Then
        txt_id.Text = "BG-001"
    Else
        txt_id.Text = CStr(Val(Microsoft.VisualBasic.Mid(dr.Item("id_barang").ToString, 4, 3)) + 1)
        If Len(txt_id.Text) = 1 Then
            txt_id.Text = "BG-00" & txt_id.Text & ""
        ElseIf Len(txt_id.Text) = 2 Then
            txt_id.Text = "BG-0" & txt_id.Text & ""
        ElseIf Len(txt_id.Text) = 3 Then
            txt_id.Text = "BG-" & txt_id.Text & ""
        End If
    End If
End Sub

这里是保存按钮的代码

 Private Sub cmd_simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_simpan.Click
    If txt_kode.Text = "" And txt_lokasi.Text = "" Then
        MsgBox("Data masih belum lengkap", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Simpan Data Barang")
        txt_kode.Focus()
    Else
        cmd = New OleDbCommand("Insert into tb_lokasi values('" & UCase(txt_id.Text) & "','" & UCase(txt_kode.Text) & "','" & UCase(txt_lokasi.Text) & "')", conn)
        cmd.ExecuteNonQuery()
        Call id_barang()
        Call bersih()
        Call tampilbrg()
        Call aturtampil()
        txt_kode.Focus()
    End If
End Sub

对于数据库,我正在使用Ms.Access

0 个答案:

没有答案