简体   繁体   中英

How to query two access database(accdb) files that have different schema?

I need your help.

Suppose there are two access database(accdb) files which have some columns with same names but some are not. For example: start

Then how to make a query to both database at the same time?

OleDbConnection Conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data 
Source=..\\DATABASE_A.accdb;");
OleDbCommand command = new OleDbCommand();
OleDbDataAdapter adapter = new OleDbDataAdapter();
DataTable dt = new DataTable();
Con.Open();
string query = "Select [JOB],[DATE] From TABLE_A WHERE [NAME] = ?";
command.CommandText = query;
command.Parameters.AddWithValue("@NAME", $someDate);

command.Connection = Conn;
adapter.SelectCommand = command;
adapter.Fill(dt);
Conn.Close();

However, how about DATABASE_B.accdb to fill the same DataTable dt but TABLE_B's column has different name?I want to form a datatable like that: result

Thanks for any suggestion.

In SQL you would use a union query .

In C# you could use LINQ Union .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM