Results 1 to 4 of 4

Thread: Please help me How can i create a new table using ado

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Posts
    3

    Unhappy Please help me How can i create a new table using ado

    I'm a beginner in using ado
    My application needs to create a DB at runtime
    Can someone give me an example on how to create tables and fields ?

    Thank You all & excuse me if my english is bad

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    sample

    VB Code:
    1. Option Explicit
    2. Dim cat As ADOX.Catalog
    3. Dim tbl As ADOX.Table
    4.  
    5. Private Sub Command1_Click()
    6.     Set cat = New ADOX.Catalog
    7.     Set tbl = New ADOX.Table
    8.  
    9.     ' create the db
    10.     cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\newDB.mdb"
    11.    
    12.     With tbl
    13.       .Name = "TestTable"
    14.       ' Create fields and append them to the
    15.       ' Columns collection of the new Table object.
    16.       With .Columns
    17.          .Append "ID COLUMN"
    18.          .Append "SetName", adVarWChar, 255
    19.          .Append "SetVal", adVarWChar, 255
    20.          .Append "Description", adVarWChar, 255
    21.       End With
    22.    End With
    23.    
    24.    ' Add the new Table to the Tables collection of the database.
    25.    cat.Tables.Append tbl
    26.    
    27.    Set cat = Nothing
    28.    Set tbl = Nothing
    29.    
    30. End Sub
    -= a peet post =-

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    You need to add a reference to 'Microsoft ADO Ext. X.X For DLL And Security' in order to use the sample.

    -= a peet post =-

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    You can also create tables using SQL

    VB Code:
    1. 'add a table with some fields
    2. sql = "CREATE TABLE TestTable (ID COUNTER, SetName TEXT(50), SetVal TEXT(255), Description TEXT(255))"
    3. db.Execute sql
    -= a peet post =-

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