This project has moved. For the latest updates, please go here.
   create a new database with Access
   taken from Example01.cs
private void Example01Main()
   // start access 
   Access.Application accessApplication = new Access.Application();

   // create database name 
   string fileExtension = GetDefaultExtension(accessApplication);
   string documentFile = string.Format("{0}\\Example01{1}", 
fileExtension); // delete old database if exists if (System.IO.File.Exists(documentFile)) System.IO.File.Delete(documentFile); // create database DAO.Database newDatabase = accessApplication.DBEngine.Workspaces[0].CreateDatabase(
documentFile, LanguageConstants.dbLangGeneral); // close access and dispose reference accessApplication.Quit(AcQuitOption.acQuitSaveAll); accessApplication.Dispose(); FinishDialog fDialog = new FinishDialog("Database saved.", documentFile); fDialog.ShowDialog(this); } /// <summary> /// returns the valid file extension for the instance. for example ".mdb" or ".accdb" /// </summary> /// <param name="application">the instance</param> /// <returns>the extension</returns> private static string GetDefaultExtension(Access.Application application) { // Access 2000 doesnt have the Version property(unfortunately) // we check for support with the EntityIsAvailable method, implemented by NetOffice if (!application.EntityIsAvailable("Version")) return ".mdb"; double Version = Convert.ToDouble(application.Version, CultureInfo.InvariantCulture); if (Version >= 12.00) return ".accdb"; else return ".mdb"; }

Last edited Jun 13, 2012 at 1:37 PM by SebastianDotNet, version 5


No comments yet.