Results 1 to 5 of 5

Thread: perform this action only once for database

  1. #1

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    perform this action only once for database

    how can I check to see if a table exist in my database and if it doesn't perform this action, if it does, don't do anything? This is my code and I only want to perform this action once.

    VB Code:
    1. 'this code modifies the existing database without overwriting user data
    2.     'create new table
    3.     Call CreateConnection(objConn)
    4.         objConn.Execute "CREATE TABLE TempDocAudio(n_id  TEXT(50))"
    5.     Call CloseConnection(objConn)
    6.    
    7.     'modify Documents and Campaign tables
    8.     Call CreateConnection(objConn)
    9.         objConn.Execute "ALTER TABLE Documents ADD COLUMN n_mp3 TEXT(50)"
    10.         'cannot use default parameters with ODBC connectivity must switch to OLEDB
    11.         objConn.Execute "ALTER TABLE Documents ADD COLUMN n_wavBol TEXT(50)DEFAULT FALSE"
    12.        
    13.         'add wespak and defender columns
    14.         objConn.Execute "ALTER TABLE Campaign ADD COLUMN c_wespakOn TEXT(50)DEFAULT 1"
    15.         objConn.Execute "ALTER TABLE Campaign ADD COLUMN c_defenderOn TEXT(50)DEFAULT 1"
    16.     Call CloseConnection(objConn)
    He who never made a mistake never made a discovery?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: perform this action only once for database

    Quote Originally Posted by Navarone
    how can I check to see if a table exist in my database
    Select count(*) from sysobjects where name = 'tableyouarelookingfor'

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: perform this action only once for database

    Use the ADOX library for complete control over design of table.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: perform this action only once for database

    so like this?

    VB Code:
    1. dim sSQL as String
    2. sSQL = "SELECT count(*) from sysobjects where name = 'TempDocAudio'"
    He who never made a mistake never made a discovery?

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: perform this action only once for database

    Quote Originally Posted by Navarone
    so like this?

    VB Code:
    1. dim sSQL as String
    2. sSQL = "SELECT count(*) from sysobjects where name = 'TempDocAudio'"
    Yep, and if your recordset = 0 it isn't there. Before putting my queries into my VB program, I always like to run them in Query Analyser to make sure they work. If you pop that one in there and use a table name you know doesn't exist, and then a table name you know does exist, you will that it will work.

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