// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Office.Interop.Access; namespace Spludlow.Office { public class Access { public static void ImportTablesODBC(string accessFilename, bool link, string sourceConnectionString, string[] tableNames) { ImportTables(accessFilename, link, "ODBC Database", sourceConnectionString, tableNames); } public static void ImportTables(string accessFilename, bool link, string sourceDatabaseType, string sourceConnectionString, string[] tableNames) { AcDataTransferType transferType = (link == true ? AcDataTransferType.acLink : AcDataTransferType.acImport); Application application = new Application(); application.OpenCurrentDatabase(accessFilename); try { foreach (string tableName in tableNames) { application.DoCmd.TransferDatabase(transferType, sourceDatabaseType, sourceConnectionString, AcObjectType.acTable, tableName, tableName, false, false); } } finally { application.CloseCurrentDatabase(); application.Quit(); } } } }