我严重陷入了错误。当我尝试从Menu.vb调用一个表单(frmRecipe)它在行上给出了一个错误,我正在尝试从Recipe表中获取最大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
的类型
答案 0 :(得分:1)
试试这个:
Return Format(Val(dr(0).ToString) + 1, "0000")