Home

Introduction to Databases

 

Description

To create a database in ADOX, you can call the Create() of the Catalog class of the ADOX library. Its syntax is:

Catalog.Create(ByVal ConnectString As String)

If you are dealing with a Microsoft SQL Server database, specify the provider as SQLOLEDB.

Here is an example:

Private Sub cmdAction_Click()
    Dim objCatalog As ADOX.Catalog
    
    Set objCatalog = New ADOX.Catalog
    
    objCatalog.Create "provider=SQLOEDB"

    Set objCatalog = Nothing
End Sub

If you are dealing with a Microsoft Access database, specify the provider as Microsoft.JET.OLEDB.4.0 (case insensitive). Here is an example:

Private Sub cmdAction_Click()
    Dim objCatalog As ADOX.Catalog
    
    Set objCatalog = New ADOX.Catalog
    
    objCatalog.Create "provider='Microsoft.Jet.OLEDB.4.0'"

    Set objCatalog = Nothing
End Sub

To specify the name of the database you want to create, assign it to an attribute named Data Source. Here is an example that creates a Microsoft Office Access 2007 compatible database named Exercise:

Private Sub cmdCreateDatabase_Click()
    Dim objCatalog As ADOX.Catalog
    
    Set objCatalog = New ADOX.Catalog
    
    objCatalog.Create "provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Exercises\Exercise.accdb"

    Set objCatalog = Nothing
End Sub

If you are creating a Microsoft Access Office 2007 database, specify the extension as .accdb. If you want to create a database compatible with previous versions of Microsoft Access, specify the extension as .mdb.

You can create the connection string and store it in a String variable. Then pass that variable to the Create() method. Here is an example:

Private Sub cmdAction_Click()
    Dim objCatalog As ADOX.Catalog
    Dim strCreator As String
    
    Set objCatalog = New ADOX.Catalog
    strCreator = "provider=Microsoft.Jet.OLEDB.4.0;'"
    strCreator = strCreator & "Data Source=C:\Exercises\Exercise.mdb'"
    
    objCatalog.Create strCreator

    Set objCatalog = Nothing
End Sub
 
 
     
 

Home Copyright © 2009-2013 FunctionX, Inc.