How to check if query entry is int?

Discussion in 'C#' started by wacamoi, May 21, 2009.

  1. #1
    usually we use
    intX=request(intX)

    yet my table field intX is type is int, so if you enter letters from a to z it will get error.

    Question is:
    How to check the query entry see if it is int or not int without showing any error?


    Best Regards,
     
    wacamoi, May 21, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Try:
    
    Dim intX
    intX = Request(intX)
    If IsNumeric(intX) Then
    'The line below is put in because the function 'isNumeric' will return true 
    'for doubles e.g: 12.3124141. So we just convert it to an integer, and depending
    'on how you insert the value into the database it will be necessary to prevent error.
    intX = Int(intX)
    Response.Write "Value is a number: " & intX
    Else
    Response.Write "Value is not a number"
    End If
    
    Code (markup):
     
    camjohnson95, May 22, 2009 IP
  3. wacamoi

    wacamoi Peon

    Messages:
    810
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you so much Camjohnson95 .



    Best Regards,
     
    wacamoi, May 22, 2009 IP
  4. yugolancer

    yugolancer Well-Known Member

    Messages:
    320
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #4
    IsNumeric is an old Visual Basic function. Therefore i would consider Parse and TryParse methods
     
    yugolancer, May 30, 2009 IP
    wacamoi likes this.