Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Using ADO, how to detect a table exists..

Using ADO, how to detect a table exists..

Scheduled Pinned Locked Moved Database
databasetutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    IrishSonic
    wrote on last edited by
    #1

    Hiya I am using ADO and need to be able to detect if a table already exists. If the table exists, I need to drop the table and create this new table. This is my code so far: // create table and don't allow any zero value records sqlcmd.Format( "CREATE TABLE Pxhsinv (Invoice varchar(30) NOT NULL,Invoice_Record varchar(8000) NOT NULL)" ); // execute the sql string pConnection->Execute(_bstr_t(sqlcmd), RecordsAffected, 1); // empty string sqlcmd.Empty(); How do I detect if the table exists already.. Thanks.

    J G 2 Replies Last reply
    0
    • I IrishSonic

      Hiya I am using ADO and need to be able to detect if a table already exists. If the table exists, I need to drop the table and create this new table. This is my code so far: // create table and don't allow any zero value records sqlcmd.Format( "CREATE TABLE Pxhsinv (Invoice varchar(30) NOT NULL,Invoice_Record varchar(8000) NOT NULL)" ); // execute the sql string pConnection->Execute(_bstr_t(sqlcmd), RecordsAffected, 1); // empty string sqlcmd.Empty(); How do I detect if the table exists already.. Thanks.

      J Offline
      J Offline
      Jason McBurney
      wrote on last edited by
      #2

      I think that if the table already exists, the database will throw an error. Could you trap it?

      1 Reply Last reply
      0
      • I IrishSonic

        Hiya I am using ADO and need to be able to detect if a table already exists. If the table exists, I need to drop the table and create this new table. This is my code so far: // create table and don't allow any zero value records sqlcmd.Format( "CREATE TABLE Pxhsinv (Invoice varchar(30) NOT NULL,Invoice_Record varchar(8000) NOT NULL)" ); // execute the sql string pConnection->Execute(_bstr_t(sqlcmd), RecordsAffected, 1); // empty string sqlcmd.Empty(); How do I detect if the table exists already.. Thanks.

        G Offline
        G Offline
        Gaurav Bindlish
        wrote on last edited by
        #3

        Run the Query - Select name from sysobjects where name like 'Pxhsinv' and type = 'U' If this query gives some record in the resultset, the table is present else not. Gaurav

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups