Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleUse ADOX to create a database
Keywordsdatabase, ADOX, create database
CategoriesDatabase
 
In the project, add references to:

    Microsoft ActiveX Data Objects 2.5 Library
    Microsoft ADO Ext. for DDL and Security

To create the database, use an ADOX.Catalog object.

To make a table, make a new ADOX.Table object. Use its Columns collection's Append method to define fields. When you are finished, use the Catalog's Tables collection's Append method to add the Table.

Use ADO to manipulate the tables.

 
Private Sub cmdCreate_Click()
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim con As ADODB.Connection

    ' Delete the database if it already exists.
    On Error Resume Next
    Kill txtDatabaseName.Text
    On Error GoTo 0

    ' Create the new database.
    Set cat = New ADOX.Catalog
    cat.Create _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & txtDatabaseName.Text & ";"

    ' Create a new table.
    Set tbl = New ADOX.Table
    tbl.Name = "TestTable"
    tbl.Columns.Append "FirstName", adVarWChar, 40
    tbl.Columns.Append "LastName", adVarWChar, 40
    cat.Tables.Append tbl

    ' Connect to the database.
    Set con = cat.ActiveConnection

    ' Insert a record.
    con.Execute "INSERT INTO TestTable VALUES ('Rod', " & _
        "'Stephens')"

    Set con = Nothing
    Set tbl = Nothing
    Set cat = Nothing

    MsgBox "Done"
End Sub
 
Note that my version of the Visual Data Manager (in the Add-Ins menu) cannot read the database created although my ADO programs can.
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated