Results 1 to 8 of 8

Thread: Create table from VB [Resolved]

  1. #1

    Thread Starter
    Addicted Member Paradox's Avatar
    Join Date
    Sep 2004
    Location
    Nairobi
    Posts
    189

    Resolved Create table from VB [Resolved]

    Hi

    does anyone know how to create tables and table fields from VB code. i am using ADO.

    craeting a patch for my application and need to add to add fields to a table in my db. (Ms Access)

    Thanks
    Last edited by Paradox; Sep 16th, 2005 at 03:12 AM.
    Peny wise pound Foolish

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Create table from VB

    You simply write a 'CREATE TABLE' command in sql and issue it through your ADO connection exactly the same as you would any other SQL query. I can't be bothered to layout the syntax for CREATE TABLE here so here's a link to W3 schools (an excewllent SQL resource BTW)

    http://www.w3schools.com/sql/sql_create.asp

  3. #3
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Create table from VB

    Paradox,

    Look in my signature for Free VB Source Code. Go to Import DBase IV files into an Access 2000 Database. This will give you all the info you need.

  4. #4
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Create table from VB

    Something like this:
    VB Code:
    1. Dim sql As String
    2.    
    3.     sql = "create table [MyTable] "
    4.     sql = sql & "([MyField1] TEXT (16), "
    5.     sql = sql & "[MyField2] DATE, "
    6.     sql = sql & "[MyField3] LONG);"
    7.    
    8.     MyConn.Execute sql      ' Create the table
    Search VB's help for Create table for more info on creating indexes etc
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  5. #5

    Thread Starter
    Addicted Member Paradox's Avatar
    Join Date
    Sep 2004
    Location
    Nairobi
    Posts
    189

    Re: Create table from VB

    Thanks for all your responses, guess dint phrase myself properly, i want to add a field to an existing table, not to create a new table.

    rgds
    Last edited by Paradox; Sep 16th, 2005 at 02:36 AM.
    Peny wise pound Foolish

  6. #6
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Create table from VB

    Paradox,

    look at the project, it won't make a difference which you want to do.

  7. #7
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Create table from VB

    You can use Alter Table
    VB Code:
    1. sql = "Alter Table [MyTable] ADD COLUMN [MyNewColumn] INTEGER"
    2. MyConn.Execute sql
    I'm not 100% sure that's the correct syntax, but it should get you started.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  8. #8

    Thread Starter
    Addicted Member Paradox's Avatar
    Join Date
    Sep 2004
    Location
    Nairobi
    Posts
    189

    Re: Create table from VB

    Thanks guys, figured it out
    Peny wise pound Foolish

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