Hi There

Pls exscuse me I am an absolute newbie. I hv setup an vb.net 2003 app that accesses and old access mbd but i need to have the db created during setup - has anyone got any advice or ideas

Thank u

Colwyn

Hi There

Pls exscuse me I am an absolute newbie. I hv setup an vb.net 2003 app that accesses and old access mbd but i need to have the db created during setup - has anyone got any advice or ideas

Thank u

Colwyn

Your post is a bit confusing. First you say you're connecting to an existing older database, and then you say you need to create it.

If you need to create the database and tables therein, you need different code than connecting to an existing database.

To create a database, you need a function similar to this:

Public Function CreateDatabase(ByVal FileName As String) As Boolean
'Instantiate the ADOX Object
Dim ADOXCatalog As ADOX.Catalog = New ADOX.Catalog
Dim oConnect As String
'Setup the connection string
oConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileName

' Try creating the database
Try
'Create the database
ADOXCatalog.Create(oConnect)
Catch ex As System.Runtime.InteropServices.COMException
Catch ex As Exception
'Show error message and return failure
MsgBox(ex.Message & vbCrLf & ex.StackTrace)
Return False Finally
'Dispose the object
ADOXCatalog = Nothing
End Try
'Return success
Return True
End Function

If on the other hand you want to connect to an existing database, you would need something like this:

Dim cmd As New OleDb.OleDbCommand
Dim cmd1 As New OleDb.OleDbCommand
Dim con As New OleDb.OleDbConnection
If (Me.txtname.Text <> "" And Me.txtadd.Text <> "") Then
cmd.Connection = con
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=
Drive where database and path to example "C:\WindowsApplication1\DATABASENAME.mdb"

con.Open()

This article has been dead for over six months. Start a new discussion instead.