Android Question Retrieving a Null Value

Discussion in 'Android Questions' started by peggjones, May 11, 2015.

  1. peggjones

    peggjones Active Member Licensed User

    How can I ignore a null value?

    When I execute code like the following

    Log(Cursor.GetString("number"))

    If number contains a null I would like to just ignore it rather than have the program fall over.

    Is there any an easy way to do this?

    Many Thanks
     
  2. Peter Simpson

    Peter Simpson Expert Licensed User

    Have you tried placing your code within the Try statement? Personally I would try the code below. If that does not work then just change your SQL query to replace Null with a 0.

    Just a quick guess as I'm typing using my phone.
    Code:
    Try
         Number = 
    Cursor.GetString("number")
    Catch
         
    Log(LastException.Message)
         
    Return
    End Try
     
    Last edited: May 11, 2015
    thedesolatesoul and eurojam like this.
  3. eurojam

    eurojam Well-Known Member Licensed User

    Code:
    If Cursor1.GetString("number") <> Null Then
      myNumber = Cursor1.GetString(
    "number")
    Else
      myNumber= 
    "NULL"    'or whatever
    End If
    you can also use Cursor1.GetDouble to retrieve numbers
     
    RauchG, DonManfred, peggjones and 2 others like this.
  4. incendio

    incendio Well-Known Member Licensed User

    Here is my version :
    Code:
    Lbl.Text = GetString(1)
    If(Lbl.Text = "null"Then Lbl.Text = ""
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice