我正在尝试从自动编号中获取自定义自动编号。但是,当数据库表中有一些数据时,它运行平稳,当数据库表中没有数据时,它会给我错误。
Private Sub CustomNo()
Dim comm As OleDbCommand
Dim commStr As String = "SELECT MAX(ID) FROM Table"
Dim RD As OleDbDataReader
Dim i As Integer
conn = New OleDbConnection(connStr)
conn.Open()
comm = New OleDbCommand(commStr, conn)
RD = comm.ExecuteReader
While RD.Read
If Not IsDBNull(RD.GetInt32(0)) = False Then
i = RD.GetInt32(0)
CustN = "ABC-" & i + 1
Custom_NoTextBox.Text = CustN
Exit While
Else
i = 0
CustN = "ABC-" & i + 1
Custom_NoTextBox.Text = CustN
End If
End While
conn.Close()
End Sub