我如何更改我的自动生成ID为其他号码

时间:2019-06-17 08:34:01

标签: vb.net ms-access

我如何让我的自动生成的ID号可以变成其他号码,现在我将我的自动生成的ID号设置为555551,如果我希望我的5555前面的4号为5424或其他4个数字可以接受。我如何编辑我的代码。

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cnn = New OleDb.OleDbConnection
        cnn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=mydata.mdb"
        'get data into list
        getNextNumber()
        RefreshData()
End Sub

Private Sub getNextNumber()
        If Not cnn.State = ConnectionState.Open Then
            'open connection
            cnn.Open()
        End If

        Dim da As New OleDb.OleDbDataAdapter("select cid from checker order by cid desc;", cnn)
        Dim dt As New DataTable
        'fill data to datatable
        da.Fill(dt)

        'offer data in data table into datagridview
        'Me.dgvData.DataSource = dt

        'close connection
        cnn.Close()

        If dt.Rows.Count > 0 Then
            txtCID.Text = (Val(dt.Rows(0)(0)) + 1).ToString.PadLeft(6, "5")
        Else
            txtCID.Text = "1".PadLeft(6, "5")
        End If

End Sub

Private Sub RefreshData()

        For i As Integer = 0 To dt.Rows.Count - 1
            dt(i)("IDstring") = dt(i)("ID").ToString.PadLeft(6, "5")
        Next

        'offer data in data table into datagridview
        Me.dgvData.DataSource = dt
        dgvData.Columns("ID").Visible = False
        dgvData.Columns("IDstring").HeaderText = "ID"
        'close connection
        cnn.Close()
End Sub

这是我的数据库结果 检查器ID:555551

0 个答案:

没有答案