-1

我想在 vb.net 中创建自动递增数,例如:-

01, 02, 03, 04 

等等..所以它是有序的。

我正在使用 VB NET 2008 连接 OleDb 到 MS Access。

它会得到这个错误

未为类型“DBNull”和类型“整数”定义运算符“+”

如果我在表中有一条空记录。但是当我在表中至少有 1 条记录时它正在工作

这是我的代码

Try
    cmd = New OleDbCommand(" SELECT MAX(sampleID) FROM 1BK ", cnnOLEDB)
    Dim dr As OleDbDataReader = cmd.ExecuteReader
    If dr.Read Then
        TextBox1.Text = dr.Item(0) + 1
    Else
        TextBox1.Text = "20120701"
    End If
Catch ex As Exception
    MsgBox(ex.Message)
End Try
4

1 回答 1

0

That is probably because the dr.Item(0) is null, and cannot be added with. I would first run a check to make sure that dr.Item(0) != null and then do the addition. If it is null, make the TextBox1.Text = [YOURSTARTERVALUE];

于 2012-07-11T01:19:32.803 回答