我严重地陷入了错误。当我尝试从Menu.vb调用表单(frmRecipe)时,它在尝试从配方表中获取最大ID的行上给出了错误,这是我的以下代码
Function Get_Max_Id() As String
Try
Dim CMD As New SqlCommand("SELECT MAX(Recipe_ID) FROM Recipe", CONN)
CMD.CommandType = CommandType.Text
Dim dr As SqlDataReader
dr = CMD.ExecuteReader
If dr.Read Then
Return Format(Val(dr(0)).ToString + 1, "0000")
Else
Return "0001"
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Recipe_id是数据库中
Varchar
的类型
最佳答案
尝试这个:
Return Format(Val(dr(0).ToString) + 1, "0000")
关于vb.net - 参数 'Expressions'无法转换为 “DBNull”类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17967055/