Here is my solution for repeated DAO tables using C #.
My application uses a central MS Access database and 8 actual databases that are referenced. The central database is stored locally in my C # application, but the application allows you to host 8 databases elsewhere. On launch, my C # application overwrites the DAO tables in the central database based on the app.config options.
In addition, this database structure is the result of the fact that my application was originally an MS Access App, which I ported to VB6. I am currently converting my application to C #. I could refuse MS Access in VB6 or C #, but this is a very simple solution for desktop computers.
In a central database, I created a table called linkedtables with three columns, TableName, LinkedTableName, and DatabaseName.
At the beginning of the application, I call this procedure
Common.RelinkDAOTables(Properties.Settings.Default.DRC_Data , Properties.Settings.Default.DRC_LinkedTables , "SELECT * FROM LinkedTables");
Default.DRC_Data - current central access folder DB Default.DRC_LinkedTables - Current folder of 8 databases
Here is the code, is it possible to repeat DAO tables in C #
public static void RelinkDAOTables(string MDBfile, string filepath, string sql) { DataTable linkedTables = TableFromMDB(MDBfile, sql); dao.DBEngine DBE = new dao.DBEngine(); dao.Database DB = DBE.OpenDatabase(MDBfile, false, false, ""); foreach (DataRow row in linkedTables.Rows) { dao.TableDef table = DB.TableDefs[row["Name"].ToString()]; table.Connect = string.Format(";DATABASE={0}{1} ;TABLE={2}", filepath, row["database"], row["LinkedName"]); table.RefreshLink(); } }
Extra code written to retrieve data from an access database and return it as a DataTable
public static DataTable TableFromOleDB(string Connectstring, string Sql) { try { OleDbConnection conn = new OleDbConnection(Connectstring); conn.Open(); OleDbCommand cmd = new OleDbCommand(Sql, conn); OleDbDataAdapter adapter = new OleDbDataAdapter(cmd); DataTable table = new DataTable(); adapter.Fill(table); return table; } catch (OleDbException) { return null; } } public static DataTable TableFromMDB(string MDBfile, string Sql) { return TableFromOleDB(string.Format(sConnectionString, MDBfile), Sql); }