Pregunta

I am badly stuck with an error. When I try to call a form (frmRecipe) from Menu.vb It gives an error on line where i am trying get maximum id from Recipe table, Here is my Code below

 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 is type of Varchar in database

¿Fue útil?

Solución

Try this:

Return Format(Val(dr(0).ToString) + 1, "0000")
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top