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: 439


Comments
You must be logged in to submit a comment.

Return