public void RunExample() { // start access Access.Application accessApplication = new Access.Application(); // create a utils instance, not need for but helpful to keep the lines of code low CommonUtils utils = new CommonUtils(accessApplication); // create database file name string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example01", Access.Tools.DocumentFormat.Normal); // 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(); // show dialog for the user(you!) HostApplication.ShowFinishDialog(null, documentFile); }
public TestResult DoTest() { Access.Application application = null; DateTime startTime = DateTime.Now; try { application = new Access.Application(); // create database name string fileExtension = GetDefaultExtension(application); string documentFile = string.Format("{0}\\Test01{1}", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), fileExtension); // delete old database if exists if (System.IO.File.Exists(documentFile)) System.IO.File.Delete(documentFile); // create database DAO.Database newDatabase = application.DBEngine.Workspaces[0].CreateDatabase(documentFile, LanguageConstants.dbLangGeneral); return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""); } catch (Exception exception) { return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""); } finally { if (null != application) { // close access and dispose reference application.Quit(AcQuitOption.acQuitSaveNone); application.Dispose(); } } }
public TestResult DoTest() { Access.Application application = null; DateTime startTime = DateTime.Now; try { application = new Access.Application(); // create database name string fileExtension = GetDefaultExtension(application); string documentFile = string.Format("{0}\\Test01{1}", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), fileExtension); // delete old database if exists if (System.IO.File.Exists(documentFile)) System.IO.File.Delete(documentFile); // create database DAO.Database newDatabase = application.DBEngine.Workspaces[0].CreateDatabase(documentFile, LanguageConstants.dbLangGeneral); return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""); } catch (Exception exception) { return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""); } finally { if (null != application) { // close access and dispose reference application.Quit(AcQuitOption.acQuitSaveNone); application.Dispose(); } } }
public void RunExample() { // start access Access.Application accessApplication = new Access.Application(); // create database name string fileExtension = GetDefaultExtension(accessApplication); string documentFile = string.Format("{0}\\Example01{1}", _hostApplication.RootDirectory, 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(); // show dialog for the user(you!) _hostApplication.ShowFinishDialog(null, documentFile); }
public void RunExample() { // start access Access.Application accessApplication = new Access.Application(); // create a utils instance, not need for but helpful to keep the lines of code low CommonUtils utils = new CommonUtils(accessApplication); // create database file name string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example01", Access.Tools.DocumentFormat.Normal); // 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(); // show dialog for the user(you!) HostApplication.ShowFinishDialog(null, documentFile); }
private void buttonQuitExample_Click(object sender, EventArgs e) { _accessApplication.Quit(AcQuitOption.acQuitSaveNone); _accessApplication.Dispose(); buttonStartExample.Enabled = true; buttonQuitExample.Enabled = false; }
public void RunExample() { // start access Access.Application accessApplication = new Access.Application(); // create a utils instance, no need for but helpful to keep the lines of code low CommonUtils utils = new CommonUtils(accessApplication); // create database file name string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example03", DocumentFormat.Normal); // 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); accessApplication.DBEngine.Workspaces[0].Close(); // setup database connection 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source= < access2007 OleDbConnection oleConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=" + documentFile); oleConnection.Open(); // create table OleDbCommand oleCreateCommand = new OleDbCommand("CREATE TABLE NetOfficeTable(Column1 Text, Column2 Text)", oleConnection); oleCreateCommand.ExecuteReader().Close(); // write some data with plain sql & close for (int i = 0; i < 20000; i++) { string insertCommand = string.Format("INSERT INTO NetOfficeTable(Column1, Column2) VALUES(\"{0}\", \"{1}\")", i, DateTime.Now.ToShortTimeString()); OleDbCommand oleInsertCommand = new OleDbCommand(insertCommand, oleConnection); oleInsertCommand.ExecuteReader().Close(); } oleConnection.Close(); // delete old file if exists string newDocumentFile = utils.File.Combine(HostApplication.RootDirectory, "Example03_Compacted", DocumentFormat.Normal); if (File.Exists(newDocumentFile)) { File.Delete(newDocumentFile); } // now we do CompactDatabase accessApplication.DBEngine.CompactDatabase(documentFile, newDocumentFile); // close access and dispose reference accessApplication.Quit(AcQuitOption.acQuitSaveAll); accessApplication.Dispose(); // show end dialog HostApplication.ShowFinishDialog(null, documentFile); }
public TestResult DoTest() { Access.Application application = null; DateTime startTime = DateTime.Now; try { Bitmap iconBitmap = new Bitmap(System.Reflection.Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("AccessTestsCSharp.Test04.bmp")); application = COMObject.Create <Access.Application>(COMObjectCreateOptions.CreateNewCore); Office.CommandBarButton commandBarBtn; // create database name string fileExtension = GetDefaultExtension(application); string documentFile = string.Format("{0}\\Test4{1}", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), fileExtension); // delete old database if exists if (System.IO.File.Exists(documentFile)) { System.IO.File.Delete(documentFile); } // create database DAO.Database newDatabase = application.DBEngine.Workspaces[0].CreateDatabase(documentFile, LanguageConstants.dbLangGeneral); // add a commandbar popup Office.CommandBarPopup commandBarPopup = (Office.CommandBarPopup)application.CommandBars["Menu Bar"].Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, System.Type.Missing, true); commandBarPopup.Caption = "commandBarPopup"; #region CommandBarButton // add a button to the popup commandBarBtn = (Office.CommandBarButton)commandBarPopup.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true); commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption; commandBarBtn.Caption = "commandBarButton"; Clipboard.SetDataObject(iconBitmap); commandBarBtn.PasteFace(); commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click); #endregion return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "")); } catch (Exception exception) { return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "")); } finally { if (null != application) { // close access and dispose reference application.Quit(AcQuitOption.acQuitSaveNone); application.Dispose(); } } }
public TestResult DoTest() { Access.Application application = null; DateTime startTime = DateTime.Now; try { application = new Access.Application(); // create database name string fileExtension = GetDefaultExtension(application); string documentFile = string.Format("{0}\\Test2{1}", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), fileExtension); // delete old database if exists if (System.IO.File.Exists(documentFile)) { System.IO.File.Delete(documentFile); } // create database DAO.Database newDatabase = application.DBEngine.Workspaces[0].CreateDatabase(documentFile, LanguageConstants.dbLangGeneral); application.DBEngine.Workspaces[0].Close(); // setup database connection 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source= < access2007 OleDbConnection oleConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=" + documentFile); oleConnection.Open(); // create table OleDbCommand oleCreateCommand = new OleDbCommand("CREATE TABLE NetOfficeTable(Column1 Text, Column2 Text)", oleConnection); oleCreateCommand.ExecuteReader().Close(); // write some data with plain sql & close for (int i = 0; i < 1000; i++) { string insertCommand = string.Format("INSERT INTO NetOfficeTable(Column1, Column2) VALUES(\"{0}\", \"{1}\")", i, DateTime.Now.ToShortTimeString()); OleDbCommand oleInsertCommand = new OleDbCommand(insertCommand, oleConnection); oleInsertCommand.ExecuteReader().Close(); } oleConnection.Close(); return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "")); } catch (Exception exception) { return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "")); } finally { if (null != application) { // close access and dispose reference application.Quit(AcQuitOption.acQuitSaveNone); application.Dispose(); } } }
public void RunExample() { // start access Access.Application accessApplication = new Access.Application(); // create a utils instance, not need for but helpful to keep the lines of code low CommonUtils utils = new CommonUtils(accessApplication); // create database file name string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example03", Access.Tools.DocumentFormat.Normal); // 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); accessApplication.DBEngine.Workspaces[0].Close(); // setup database connection 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source= < access2007 OleDbConnection oleConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=" + documentFile); oleConnection.Open(); // create table OleDbCommand oleCreateCommand = new OleDbCommand("CREATE TABLE NetOfficeTable(Column1 Text, Column2 Text)", oleConnection); oleCreateCommand.ExecuteReader().Close(); // write some data with plain sql & close for (int i = 0; i < 20000; i++) { string insertCommand = string.Format("INSERT INTO NetOfficeTable(Column1, Column2) VALUES(\"{0}\", \"{1}\")", i, DateTime.Now.ToShortTimeString()); OleDbCommand oleInsertCommand = new OleDbCommand(insertCommand, oleConnection); oleInsertCommand.ExecuteReader().Close(); } oleConnection.Close(); // delete old file if exists string newDocumentFile = string.Format("{0}\\CompactDatabase{1}", HostApplication, utils.File.FileExtension(Access.Tools.DocumentFormat.Normal)); if (File.Exists(newDocumentFile)) File.Delete(newDocumentFile); // now we do CompactDatabase accessApplication.DBEngine.CompactDatabase(documentFile, newDocumentFile); // close access and dispose reference accessApplication.Quit(AcQuitOption.acQuitSaveAll); accessApplication.Dispose(); // show dialog for the user(you!) HostApplication.ShowFinishDialog(null, documentFile); }
void IDTExtensibility2.OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom) { try { if (null != _accessApplication) { _accessApplication.Dispose(); } } catch (Exception exception) { string message = string.Format("An error occured.{0}{0}{1}", Environment.NewLine, exception.Message); MessageBox.Show(message, _progId, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void Dispose() { switch (_officeApp) { case "Excel": _excelApplication.Dispose(); break; case "Word": _wordApplication.Dispose(); break; case "Outlook": _outlookApplication.Dispose(); break; case "Power Point": _powerpointApplication.Dispose(); break; case "Access": _accessApplication.Dispose(); break; case "Project": _accessApplication.Dispose(); break; case "Visio": _accessApplication.Dispose(); break; default: throw new ArgumentOutOfRangeException("officeApp"); } }
public void RunExample() { // start access Access.Application accessApplication = new Access.Application(); // create database name string fileExtension = GetDefaultExtension(accessApplication); string documentFile = string.Format("{0}\\Example02{1}", _hostApplication, 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); accessApplication.DBEngine.Workspaces[0].Close(); // setup database connection 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source= < access2007 OleDbConnection oleConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=" + documentFile); oleConnection.Open(); // create table OleDbCommand oleCreateCommand = new OleDbCommand("CREATE TABLE NetOfficeTable(Column1 Text, Column2 Text)", oleConnection); oleCreateCommand.ExecuteReader().Close(); // write some data with plain sql & close for (int i = 0; i < 1000; i++) { string insertCommand = string.Format("INSERT INTO NetOfficeTable(Column1, Column2) VALUES(\"{0}\", \"{1}\")", i, DateTime.Now.ToShortTimeString()); OleDbCommand oleInsertCommand = new OleDbCommand(insertCommand, oleConnection); oleInsertCommand.ExecuteReader().Close(); } oleConnection.Close(); // close access and dispose reference accessApplication.Quit(AcQuitOption.acQuitSaveAll); accessApplication.Dispose(); // show dialog for the user(you!) _hostApplication.ShowFinishDialog(null, documentFile); }
public void RunExample() { // start access Access.Application accessApplication = new Access.Application(); // create database name string fileExtension = GetDefaultExtension(accessApplication); string documentFile = string.Format("{0}\\Example02{1}", _hostApplication, 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); accessApplication.DBEngine.Workspaces[0].Close(); // setup database connection 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source= < access2007 OleDbConnection oleConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=" + documentFile); oleConnection.Open(); // create table OleDbCommand oleCreateCommand = new OleDbCommand("CREATE TABLE NetOfficeTable(Column1 Text, Column2 Text)", oleConnection); oleCreateCommand.ExecuteReader().Close(); // write some data with plain sql & close for (int i = 0; i < 1000; i++) { string insertCommand = string.Format("INSERT INTO NetOfficeTable(Column1, Column2) VALUES(\"{0}\", \"{1}\")", i, DateTime.Now.ToShortTimeString()); OleDbCommand oleInsertCommand = new OleDbCommand(insertCommand, oleConnection); oleInsertCommand.ExecuteReader().Close(); } oleConnection.Close(); // close access and dispose reference accessApplication.Quit(AcQuitOption.acQuitSaveAll); accessApplication.Dispose(); // show dialog for the user(you!) _hostApplication.ShowFinishDialog(null, documentFile); }
public void RunExample() { // start access Access.Application accessApplication = new Access.Application(); // create database name string fileExtension = GetDefaultExtension(accessApplication); string documentFile = string.Format("{0}\\Example01{1}", _hostApplication.RootDirectory, 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(); // show dialog for the user(you!) _hostApplication.ShowFinishDialog(null, documentFile); }
public TestResult DoTest() { Access.Application application = null; DateTime startTime = DateTime.Now; try { application = new Access.Application(); // create database name string fileExtension = GetDefaultExtension(application); string documentFile = string.Format("{0}\\Test3{1}", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), fileExtension); // delete old database if exists if (System.IO.File.Exists(documentFile)) System.IO.File.Delete(documentFile); // create database DAO.Database newDatabase = application.DBEngine.Workspaces[0].CreateDatabase(documentFile, LanguageConstants.dbLangGeneral); application.DBEngine.Workspaces[0].Close(); // setup database connection 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source= < access2007 OleDbConnection oleConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=" + documentFile); oleConnection.Open(); // create table OleDbCommand oleCreateCommand = new OleDbCommand("CREATE TABLE NetOfficeTable(Column1 Text, Column2 Text)", oleConnection); oleCreateCommand.ExecuteReader().Close(); // write some data with plain sql & close for (int i = 0; i < 20000; i++) { string insertCommand = string.Format("INSERT INTO NetOfficeTable(Column1, Column2) VALUES(\"{0}\", \"{1}\")", i, DateTime.Now.ToShortTimeString()); OleDbCommand oleInsertCommand = new OleDbCommand(insertCommand, oleConnection); oleInsertCommand.ExecuteReader().Close(); } oleConnection.Close(); // now we do CompactDatabase string newDocumentFile = string.Format("{0}\\CompactDatabase{1}", Environment.CurrentDirectory, fileExtension); if (File.Exists(newDocumentFile)) File.Delete(newDocumentFile); application.DBEngine.CompactDatabase(documentFile, newDocumentFile); return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""); } catch (Exception exception) { return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""); } finally { if (null != application) { // close access and dispose reference application.Quit(AcQuitOption.acQuitSaveNone); application.Dispose(); } } }
public TestResult DoTest() { Access.Application application = null; DateTime startTime = DateTime.Now; try { Bitmap iconBitmap = new Bitmap(System.Reflection.Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("AccessTestsCSharp.Test04.bmp")); application = new Access.Application(); Office.CommandBarButton commandBarBtn; // create database name string fileExtension = GetDefaultExtension(application); string documentFile = string.Format("{0}\\Test4{1}", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), fileExtension); // delete old database if exists if (System.IO.File.Exists(documentFile)) System.IO.File.Delete(documentFile); // create database DAO.Database newDatabase = application.DBEngine.Workspaces[0].CreateDatabase(documentFile, LanguageConstants.dbLangGeneral); // add a commandbar popup Office.CommandBarPopup commandBarPopup = (Office.CommandBarPopup)application.CommandBars["Menu Bar"].Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, System.Type.Missing, true); commandBarPopup.Caption = "commandBarPopup"; #region CommandBarButton // add a button to the popup commandBarBtn = (Office.CommandBarButton)commandBarPopup.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true); commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption; commandBarBtn.Caption = "commandBarButton"; Clipboard.SetDataObject(iconBitmap); commandBarBtn.PasteFace(); commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click); #endregion return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""); } catch (Exception exception) { return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""); } finally { if (null != application) { // close access and dispose reference application.Quit(AcQuitOption.acQuitSaveNone); application.Dispose(); } } }