C# program that interfaces with MS Access: Create a new Access database file

1. Open a new Visual C# .NET windows application. Name the project CreateDatabase.

2. In Solution Explorer, right-click the References node and select Add Reference. On the COM tab, select “Microsoft ADO Ext. 2.8 for DDL and Security”, and then click OK.

3. Design a form. Add a Textbox and a Button

4. Set Name property of Textbox to “txtdatabaseName”.

5. Set Name property of Button to “btnCreateDB” and text property to “Create Database”.

6. In the code behind file import the library Microsoft ADO Ext. 2.8 for DDL and Security using: using ADOX;

7. Double click on the Button and pest the following code into the “btnCreateDB_Click” event

CatalogClass cat = new CatalogClass();
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + txtdatabaseName.Text + ".mdb;" +
"Jet OLEDB:Engine Type=5"); // Create databse
MessageBox.Show("Database created successfully."); // Show confirmation to user
txtdatabaseName.Text = ""; // Clear input box
catch (Exception ex)
cat = null;

8. Press F5 to build and run the project.

9. Put your database name with location like c:\MyAccessDB in the text box and then press the “Create Database” Button. An access database by the name MyAccessDB.mdb will be created at the specified location.

No comments yet.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.

    Click to Rate This Article