Creating an access database in code (1 Viewer)

smudge

New member
Local time
Today, 04:21
Joined
Sep 9, 2006
Messages
2
I haven't used VB since version 4 and it was fairly easy to create an access database in code.

I want to get in to .NET development and bought a copy of VS2003 to play with. VB is totally different and it's confusing me something awful. Is there a way of creating an access database and adding tables in code?

I've looked in the help files, tried doing google searches but I don't seem to be able to find anything.

Thanks

Carl
 

skea

Registered User.
Local time
Today, 06:21
Joined
Dec 21, 2004
Messages
342
Use ADOX Library. Attached is the dll and below is some sample code.
Hope it helps.
Code:
Imports System.Runtime.InteropServices
Imports ADOX
Public Class Form1
    'Shows how to create an Access database and append tables, fields, indexes using ADOX. Don't forget
    'a reference to ADOX (Microsoft ADO Ext. 2.x for DDL and Security)
    Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
        Dim ADOXcatalog As New Catalog
        Dim ADOXtable As New Table
        Dim myConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "c:\newdata.mdb"
        Try
            ADOXcatalog.Create(myConn)
            'name table, append fields to table
            ADOXtable.Name = "tblCustomers"
            ADOXtable.Columns.Append("First_Name", ADOX.DataTypeEnum.adVarWChar, 40)
            ADOXtable.Columns.Append("customerID", ADOX.DataTypeEnum.adInteger)
            ADOXtable.Columns.Append("Address", ADOX.DataTypeEnum.adVarWChar, 20)
            'append tables to database
            ADOXcatalog.Tables.Append(ADOXtable)
        Catch ex As Exception
            MessageBox.Show("Error in btnCreate_Click():" & ex.Message)
        Finally
            ADOXtable = Nothing
            ADOXcatalog = Nothing
        End Try
    End Sub

End Class
 

Attachments

  • Interop.ADOX.zip
    9 KB · Views: 280

smudge

New member
Local time
Today, 04:21
Joined
Sep 9, 2006
Messages
2
Cool. Thanks :D
 

Users who are viewing this thread

Top Bottom