public static int CreateDataBase(string path) { Access.Application AccessAplication = new Access.Application(); AccessAplication.NewCurrentDatabase(path,Access.AcNewDatabaseFormat.acNewDatabaseFormatUserDefault); AccessAplication.CloseCurrentDatabase(); AccessAplication.Quit(); return 0; }
private void TextToAccessConvert(string path) { var accApplication = new ACCESS.Application(); var pieces = path.Split('\\'); string directory = ""; foreach (var piece in pieces) { if (piece.Contains(".")) { continue; } directory += piece; directory += "\\"; } if (File.Exists(path)) { File.Delete(path); } accApplication.NewCurrentDatabase(path); accApplication.DoCmd.TransferText(TransferType: ACCESS.AcTextTransferType.acImportDelim, TableName: "AMT", FileName: directory + "tempAMT.txt", HasFieldNames: true); accApplication.DoCmd.TransferText(TransferType: ACCESS.AcTextTransferType.acImportDelim, TableName: "AMT_Proteins", FileName: directory + "tempAMT_Proteins.txt", HasFieldNames: true); accApplication.DoCmd.TransferText(TransferType: ACCESS.AcTextTransferType.acImportDelim, TableName: "AMT_to_Protein_Map", FileName: directory + "tempAMT_to_Protein_Map.txt", HasFieldNames: true); accApplication.CloseCurrentDatabase(); accApplication.Quit(); File.Delete(directory + "tempAMT.txt"); File.Delete(directory + "tempAMT_Proteins.txt"); File.Delete(directory + "tempAMT_to_Protein_Map.txt"); }
private void FileCreation() { if (!File.Exists(strAccessFilePath)) { if (!new DirectoryInfo(strAccessFilePath).Exists) { new DirectoryInfo(new FileInfo(strAccessFilePath).DirectoryName).Create(); } Access.Application _accessApp = new Access.Application(); _accessApp.Visible = false; _accessApp.NewCurrentDatabase(strAccessFilePath); _accessApp.CloseCurrentDatabase(); _accessApp.Quit(Access.AcQuitOption.acQuitSaveAll); base.releaseObject(_accessApp); base.ClearnGarbage(); } else { string _conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + this.strAccessFilePath + "'"; using (OleDbConnection _connection = new OleDbConnection(_conn)) { string[] restrictions = new string[4]; restrictions[2] = this.strAccessTableName; _connection.Open(); DataTable dbTbl = _connection.GetSchema("Tables", restrictions); if (dbTbl != null) { if (dbTbl.Rows.Count > 0) { dbTbl.Dispose(); dbTbl = null; throw new Exception("table is already exists"); } else { dbTbl.Dispose(); dbTbl = null; } } } } }
public static void CreateAccess() { try { //create access database AccessAPP.NewCurrentDatabase(path + fileName, Microsoft.Office.Interop.Access.AcNewDatabaseFormat.acNewDatabaseFormatAccess2007, Type.Missing); releaseObject(AccessAPP); } catch (Exception e) { Console.WriteLine("Could not create: " + fileName); } }
public void ConvertToDbFormat(string path) { var accApplication = new ACCESS.Application(); var pieces = path.Split('\\'); string directory = ""; foreach (var piece in pieces) { if (piece.Contains(".")) { continue; } directory += piece; directory += "\\"; } if (File.Exists(path)) { File.Delete(path); } accApplication.NewCurrentDatabase(path); accApplication.DoCmd.TransferText(TransferType: ACCESS.AcTextTransferType.acImportDelim, TableName: "T_Mass_Tags", FileName: directory + "tempMassTags.txt", HasFieldNames: true); accApplication.DoCmd.TransferText(TransferType: ACCESS.AcTextTransferType.acImportDelim, TableName: "T_Mass_Tags_NET", FileName: directory + "tempMassTagsNet.txt", HasFieldNames: true); accApplication.DoCmd.TransferText(TransferType: ACCESS.AcTextTransferType.acImportDelim, TableName: "T_Proteins", FileName: directory + "tempProteins.txt", HasFieldNames: true); accApplication.DoCmd.TransferText(TransferType: ACCESS.AcTextTransferType.acImportDelim, TableName: "T_Mass_Tags_to_Protein_Map", FileName: directory + "tempMassTagToProteins.txt", HasFieldNames: true); accApplication.DoCmd.TransferText(TransferType: ACCESS.AcTextTransferType.acImportDelim, TableName: "T_Analysis_Description", FileName: directory + "tempAnalysisDescription.txt", HasFieldNames: true); accApplication.DoCmd.TransferText(TransferType: ACCESS.AcTextTransferType.acImportDelim, TableName: "V_Filter_Set_Overview_Ex", FileName: directory + "tempFilterSet.txt", HasFieldNames: true); accApplication.CloseCurrentDatabase(); accApplication.Quit(); File.Delete(directory + "tempMassTags.txt"); File.Delete(directory + "tempPeptides.txt"); File.Delete(directory + "tempModInfo.txt"); File.Delete(directory + "tempMassTagsNet.txt"); File.Delete(directory + "tempProteins.txt"); File.Delete(directory + "tempMassTagToProteins.txt"); File.Delete(directory + "tempAnalysisDescription.txt"); File.Delete(directory + "tempFilterSet.txt"); }