Results 1 to 29 of 29

Thread: VB.NET - Create new MS Access Database using ADOX

Threaded View

  1. #1

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    VB.NET - Create new MS Access Database using ADOX

    VB Code:
    1. Private Sub Command1_Click()
    2. 'Shows how to create an Access 2000 database and append tables, fields, indexes using ADOX. Don't forget
    3. 'a reference to ADOX (Microsoft ADO Ext. 2.x for DDL and Security)
    4.   Dim ADOXcatalog As New ADOX.Catalog
    5.   Dim ADOXtable As New Table
    6.   Dim ADOXindex As New ADOX.Index
    7.  
    8.    On Error GoTo errhandler
    9.   ADOXcatalog.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "c:\newdata.mdb"
    10.  
    11.   On Error Resume Next
    12.  
    13.   ADOXcatalog.ActiveConnection = _
    14. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
    15. & "c:\newdata.mdb"
    16.  
    17.   'name table, append fields to table
    18.   ADOXtable.Name = "Employees"
    19.   ADOXtable.Columns.Append "LastName", adVarWChar, 40
    20.   ADOXtable.Columns.Append "ID", adInteger
    21.   ADOXtable.Columns.Append "Department", adVarWChar, 20
    22.  
    23.   'append tables to database
    24.   ADOXcatalog.Tables.Append ADOXtable
    25.  
    26.  
    27.   'internal index on two fields
    28.   ADOXindex.Name = "TwoColumnsIndex" 'name of index
    29.   ADOXindex.Columns.Append "LastName"
    30.   ADOXindex.Columns.Append "ID"
    31.  
    32.   ADOXtable.Indexes.Append ADOXindex
    33. errhandler:
    34.   If Err.Number = -2147217897 Then
    35.     MsgBox "Database already exists"
    36. ElseIf Err.Number <> 0 Then
    37.     MsgBox "Err " & Err.Description & "; operation not complete"
    38. End If
    39. Set ADOXtable = Nothing
    40. Set ADOXindex = Nothing
    41. Set ADOXcatalog = Nothing
    42. End Sub
    Last edited by Pirate; Aug 10th, 2003 at 09:50 AM.

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