Making sure an entry exists in SQLite

Discussion in 'Questions (Windows Mobile)' started by N1c0_ds, Nov 30, 2008.

  1. N1c0_ds

    N1c0_ds Active Member Licensed User

    Let's say you try to get information from a line with a unique ID that doesn't exist in SQLite. It creates an error and causes big problems with my application.

    Would there be a way to return a nice error message instead?


    In context:
    Gecko uses a unique ID to get application info from an SQLite database and uses this information to either get an application based on a command and close (command line mode) or display the information and offer options (user-friendly mode). If it creates an error, it can start a chain reaction and cause more problems.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can use:
    Code:
    Sub App_Start
     cmdID.AddParameter(
    "id")
     cmdID.CommandText = 
    "SELECT count(*) FROM table WHERE col = @id"
     ...
    End Sub

    Sub IDExists (id)
     cmdID.SetParameter(
    "id",id)
     reader.Value = cmdID.ExecuteReader
     reader.ReadNextRow
     res = reader.GetValue(
    0
     reader.close 
     
    if res > 0 then return true else return false
    End Sub

    Usage example: 
    If IDExists("someid"then ...
     
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