Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Access database file (accdb) from VB.Net

Status
Not open for further replies.

g33man

Programmer
Dec 22, 2006
50
CA
First, I've got to say how difficult it has been trying to find this solution. There are a few suggestions found with Google, but none has worked for me. My programming environment is Visual Studio Express 2013. My computer also has Office Pro Plus 2010 installed.
My most recent attempt uses ADOX, and the website I got this sample code from told me I needed to add the ADOX Resource. I think I did it correctly (there were no directions), however I get a compile error that "ADOX.Catalog() is not defined".
Arghh!
Suggestions are welcome.
Mike
 
It's a bit unclear what you're trying to do. Create a new, empty .accdb file programmatically?
If so, off the top of my head, there's two methods I'd try first: Instantiate an Access process and throw VBA macro commands at it to open and save a new DB file, or embed a copy of an empty .accdb file in your application as a resource and export it (using the resourcestream and filestream classes).
 
Hi jasen,
Thanks for your response. My objective is stated in the Subject:, but I forgot to restate it in my message - apologies. Since my post, I have figured out my issue (I was not adding a Resource to my VB.Net project correctly). For any others looking for a solution, here is how I did it:

1. Add the COM Reference, "Microsoft ADO Ext. 6.0 for DLL and Security" to your project.
2. Add "Imports System.Data.OleDb" to your project.
3. The code:
Code:
' create the empty DB file
Dim cat As New ADOX.Catalog()
cat.Create("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\data\mydata.accdb")
cat = Nothing

' create the empty table in the DB file
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\data\mydata.accdb" & ";Persist Security Info=True")
conn.Open()
Dim cmd As New OleDb.OleDbCommand("", conn)
cmd.CommandText = "CREATE TABLE ICM (cn CHAR, mail CHAR, userCertificate CHAR);"
cmd.ExecuteNonQuery()
conn.Close()

Cheers,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top