How to Create an Access Database by using ADOX and Visual C# .NET

Build an Access Database:
  1. Open a new Visual C# .NET console application.
  2. In Solution Explorer, right-click the References node and select Add Reference.
  3. On the COM tab, select Microsoft ADO Ext. 2.7 for DDL and Security, click Select to add it to the Selected Components, and then click OK.
  4. Delete all of the code from the code window for Class1.cs.
  5. Paste the following code into the code window,
    1. using System;  
    2. using ADOX;  
    3.   
    4. private void btnCreate_Click(object sender, EventArgs e)  
    5. {  
    6.     ADOX.CatalogClass cat = new ADOX.CatalogClass();  
    7.   
    8.     cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=D:\\NewMDB.mdb;" + "Jet OLEDB:Engine Type=5");  
    9.     MessageBox.Show("Database Created Successfully");  
    10.     cat = null;  
    11. }  
Ebook Download
View all
Learn
View all