I have looked far and wide, in the deepest darkest corners of the internet, but for the life of me, I can not find the correct way to open a NEW Access file and then using vb.net to write data in the database..
The keywords here are NEW database, I don't want to open an existing file.
Is this even possible?
Thanks in advance!
I have finally found the way, thanks to a co-worker of mine
Neither ADO.NET nor ActiveX Data Object (ADO) provides the means to create Microsoft Access Database. However, we can create Access databases by using the Microsoft Jet OLE DB Provider and Microsoft ADO Ext. 2.7 for DDL and Security (ADOX) with the COM Interop layer. To do so, select References from the Project Menu, choose the COM tab, and add a reference to Microsoft ADO Ext. 2.7 for DDL and Security; then you can use this function.
When you have done this, use the following snippet to create a database
Public Class Form1
Private Sub btnLoad_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnLoad.Click
CreateAccessDatabase("C:\test\testDB.mdb")
MsgBox("Database created")
End Sub
Public Function CreateAccessDatabase( ByVal DatabaseFullPath As String) As Boolean
Dim bAns As Boolean
Dim cat As New ADOX.Catalog()
Try
Dim sCreateString As String
sCreateString =_
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
DatabaseFullPath
cat.Create(sCreateString)
bAns = True
Catch Excep As System.Runtime.InteropServices.COMException
bAns = False
Finally
cat = Nothing
End Try
Return bAns
End Function
End Class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With