DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: table exist

  1. #1
    gamal Guest

    table exist


    how do you check if some table exists in you db or not using VB?
    for example
    i use the the code
    if(table_name) then
    debug.Print "it is existing"
    endif
    i found the code ignore the checking because i have the table in db?
    and i do not get the message "it is existing"
    so how to write the right code?
    i also tried the same code with the object which i used to create the table
    and i got the same result.

    if(object_name)
    debug.print " it is existing"
    endif

  2. #2
    dnagel Guest

    Re: table exist

    yourcode snips seem a little 'simple'...

    What is table_name, an object, a string, a recordset?

    "Select 'SomeTableName' from Table_name"
    If executed and the table does exist you'll get "SomeTableName"
    as the only field and record in the recordset, if not then you'll get
    a DB error because the table does not exist...

    There are other ways of doing this but they get pretty specific
    to your type of database.

    D.


    "gamal" <gamalt@yahoo.com> wrote in message news:3b32410f$1@news.devx.com...
    >
    > how do you check if some table exists in you db or not using VB?
    > for example
    > i use the the code
    > if(table_name) then
    > debug.Print "it is existing"
    > endif
    > i found the code ignore the checking because i have the table in db?
    > and i do not get the message "it is existing"
    > so how to write the right code?
    > i also tried the same code with the object which i used to create the

    table
    > and i got the same result.
    >
    > if(object_name)
    > debug.print " it is existing"
    > endif




  3. #3
    George Shubin Guest

    Re: table exist

    "gamal" <gamalt@yahoo.com> wrote in message news:3b32410f$1@news.devx.com...
    >
    > how do you check if some table exists in you db or not using VB?



    Here's a function I use to determine if a table exists or not.

    Function IsTable(sTableName As String) As Boolean
    'Determines if a data table exists in a database
    Dim oDb As adodb.Connection
    Dim oRs As adodb.Recordset
    Set oDb = New adodb.Connection
    oDb.CursorLocation = adUseServer
    oDb.Open "---Put your connection string here---"
    Set oRs = oDb.OpenSchema(adSchemaTables, Array(Empty, Empty, sTableName,
    "TABLE"))
    If Not oRs.EOF Then
    IsTable = True
    Else
    IsTable = False
    End If
    oRs.Close
    Set oRs = Nothing
    oDb.Close
    Set oDb = Nothing
    End Function





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center