Register   |  Login
You are hereArticles
 Article Details
Create MS Access file programmatically

Sometimes we may have to create a MS Access database files programmatically. Later on we might need them for our application to use.

 Lets see how easy to create a MS access file from code.

Create a new windows forms project from VS 2005/VS2008 and add a com reference of Microsoft ADO Ext. 6.0 for DDL and Security from the reference window



Copy paste the following code.

 

            saveFileDialog1.Filter = "txt files (*.txt)|*.txt|MS Access(*.mdb)|*.mdb| All files (*.*)|*.*";

            saveFileDialog1.FilterIndex = 2;

            saveFileDialog1.RestoreDirectory = true;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)

            {

                ADOX.CatalogClass cat = new ADOX.CatalogClass();

                string create = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + saveFileDialog1.FileName + "; Jet OLEDB:Engine Type=5";

                cat.Create(create);

                cat = null;

            }

This code creates a MS Access file at the user selected location in the save file dialog window.

Thats it... We are done.


Written By: Kumaravel
Date Posted: 1/5/2009
Number of Views: 1112


Comments
lu juan Says:
4/5/2011 5:24:57 PM

My favorite part of the suite is Microsoft Office 2010 . You can use it like a fancy clipboard, but Office 2010 is much more powerful and useful.So, I'm forced to pay for an upgrade to Microsoft Office that I did not want.For the price, you can't go wrong with Outlook 2010 Home & Student. And, I may or may not be able to use the Product Key on the package I purchased to activate only Word, Excel, Microsoft outlook 2010PowerPoint and OneNote, the programs I thought I was buying. The only answer was to go to MS Office, or have everyone else in the world switch to Office 2007 .The instructions on the Microsoft website for activating Office imply that the full Microsoft Office 2007 Professional suite is the only version eligible for proper licensing.


You must be logged in to submit a comment.

Return