我被一个错误严重困扰。当我尝试从 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
数据库中的类型