/// <summary> /// 从csv文件导入到access库 /// </summary> /// <param name="tableName"></param> /// <param name="dbFileName"></param> public static void ImportFromCsv(string tableName, string apptemppath, string path) { Microsoft.Office.Interop.Access.ApplicationClass oAccess = new Microsoft.Office.Interop.Access.ApplicationClass(); oAccess.Visible = false; if (oAccess.AutomationSecurity != Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityLow) { oAccess.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityLow; } try { oAccess.OpenCurrentDatabase(apptemppath, false, "emed"); //oAccess.DoCmd.DeleteObject(Microsoft.Office.Interop.Access.AcObjectType.acTable, tableName); oAccess.DoCmd.TransferText(Microsoft.Office.Interop.Access.AcTextTransferType.acImportDelim, "", tableName, path + tableName + ".csv", true, "", 0); oAccess.CloseCurrentDatabase(); oAccess.DoCmd.Quit(Microsoft.Office.Interop.Access.AcQuitOption.acQuitSaveNone); System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccess); oAccess = null; } catch (Exception ex) { throw ex; } }
private void SetByPassKey() { var oAccess = new Microsoft.Office.Interop.Access.ApplicationClass(); try { oAccess.OpenCurrentDatabase(textBoxFileMDB.Text, true, textBoxAccessPassword.Text); if (checkBoxAllowDevelopmentMode.Checked) oAccess.DoCmd.RunMacro("MacroEnableByPassKey", 1, 1); else oAccess.DoCmd.RunMacro("MacroDisableByPassKey", 1, 1); } catch (Exception) { throw; } finally { oAccess.Quit(Microsoft.Office.Interop.Access.AcQuitOption.acQuitSaveAll); } }