none
vb.net 2012 do I need to convert string to integer RRS feed

  • Question

  • In a vb.net 2012 application I have the following code that works:    
    Protected _schoolyear As Integer
        Protected _schoolyearcheck As String   
        If (IsDBNull(_schoolyearcheck)) Or (Not IsNumeric(_schoolyearcheck)) Or CInt(_schoolyearcheck < 2000) Or (CInt(_schoolyearcheck) = _schoolyear) Then
                _schoolyear = _schoolyear
            ElseIf CInt(_schoolyearcheck) + 1 = _schoolyear Then
                _schoolyear = CInt(_schoolyearcheck)
            End If
    However I am wondering about the _schoolyearcheck field. I have a funciton call to the sql server database that really returns an integer value. However I
    am concerned that the call may return a null or something that is not numeric. That is why I am using a string value. Due to that fact I am converting the
    string to an interger in the the code Above.  Thus can you show me code that would be better to use than converting all the values listed above?

    Friday, August 2, 2019 3:53 PM

Answers

  • Hi Wendy,

    If the value being returned is really an integer, you don't need to do any of that.

    Just check for ISDBNULL and then convert the value to integer.

    Please post the entire code including the DB part so we can help you.

    ps: use "OrElse" instead of "Or" ;)

    Friday, August 2, 2019 4:29 PM

All replies

  • Do you have two columns defined in the database?  Are they related to the two variables you are working with?  If so how are they defined in the database?  This is very confusing.  See if you can describe what you are doing exactly.

    Search Documentation

    SerialPort Info

    Multics - An OS ahead of its time.

     "Those who use Application.DoEvents have no idea what it does

        and those who know what it does never use it."    former MSDN User JohnWein


    • Edited by dbasnett Friday, August 2, 2019 4:15 PM
    Friday, August 2, 2019 4:11 PM
  • Hi Wendy,

    If the value being returned is really an integer, you don't need to do any of that.

    Just check for ISDBNULL and then convert the value to integer.

    Please post the entire code including the DB part so we can help you.

    ps: use "OrElse" instead of "Or" ;)

    Friday, August 2, 2019 4:29 PM