CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2001
    Posts
    9

    checking database tables

    how can i check to see if a database table exists?

    is there a simple expression to handle this or do i need to figure out some way of looping through all the tables in the database and checking them one by one?


  2. #2
    Join Date
    Aug 2000
    Location
    England
    Posts
    185

    Re: checking database tables

    You could trap any error that occurs - if one does then the table does not exist, i.e

    On Error Goto notExist
    strSql = "Select * from <table>"
    db.execute strSql

    resumeNext:

    notExist:
    tableNotExist = true
    resume resumeNext

    Andrew


  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: checking database tables

    If you are using Access you can execute the following SQL

    Select Name from MSysObjects where Type = 1

    1-All tables
    2-System Databases
    3-Objects(Tables,Dtabase,Relationships,Forms,Modules,SysRelationships,Scripts)
    4-ODBC linked tables
    5-Queries
    6-Access linked tables




    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  4. #4
    Join Date
    Mar 2001
    Location
    charlotte,nc
    Posts
    84

    Re: checking database tables

    if still a problem, this worked for me,

    'Load tables/Recordsets
    With db
    Err.Clear
    set rsCatalog = .OpenRecordset(AP_rsCATLG, dbOpenDynaset)
    If Err.Number = 3078 then
    'add table
    GetMissingTable "CatalogOrders"
    set rsCatalog = .OpenRecordset(AP_rsCATLG, dbOpenDynaset)
    Err.Clear
    End If




    Elizabeth

  5. #5
    Join Date
    Aug 2001
    Posts
    9

    Re: checking database tables

    thanks people, i went for the error trap method in the end


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured