SQL Table Exists?

Discussion in 'Questions (Windows Mobile)' started by tsteward, Apr 28, 2008.

  1. tsteward

    tsteward Active Member Licensed User

    How can I find out if a table exists in my sl3 database without it throwing up a window?

    Thanks
    Tony
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can use the sqlite_master table:
    Code:
    cmd.CommandText = "SELECT COUNT(name) FROM sqlite_master WHERE type = 'table' and name = 'TableYouAreSearchingFor'" 
        Reader.Value = cmd.ExecuteReader
        
    If reader.GetValue(0) > 0 Then
            ...
        
    End If
        Reader.Close
     
  3. tsteward

    tsteward Active Member Licensed User

    Thanks Erel that works a treat.
    Why can I find info like that as I wish to learn not just ask questions?

    Also

    What is the best method for testing if a record exists.
    such as WHERE 'ID' = Smith

    Thanks Heaps
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    The best source of SQLite information is: www.sqlite.org

    You can use COUNT to check if more than 0 records were returned (similar to my previous query).
     
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