Question:
I am working with an existing commercial MS Visual Foxpro application and must retrieve data from the database directly using a C # application. Unfortunately, not all tables are stored in the same database, some of the records are stored in the database, broken down by year. How to create a query to these two databases using a single connection?
I am using Microsoft OLE DB Provider for Visual FoxPro 9.0 (SP2)
Additional Information:
In fact, customer information is stored in one database, and the customer’s purchase history stores a database broken down by year. Therefore, I am trying to create a simple request for listing customers and their last purchase from this year.
In graphical form, the db file structure looks like this:
Data\ +-2009\ | +-MyDB.dbc | +-Sales.dbf +-2010\ | +-MyDB.dbc | +-Sales.dbf +-MyDB.dbc +-Customers.dbf
Currently, I can connect to each database separately and request them:
// This works to connect to the customer DB string connectionPath1 = @"Provider=vfpoledb.1;Data Source=E:\Data\MyDB.dbc"; OleDbConnection conn1 = new OleDbConnection(connectionPath1); OleDbCommand command1 = new OleDbCommand(@"SELECT * FROM Customers", conn1); OleDbDataReader reader1 = command1.ExecuteReader(); // This works to connect to the annual sales record DB string connectionPath2 = @"Provider=vfpoledb.1;Data Source=E:\Data\2010\MyDB.dbc"; OleDbConnection conn2 = new OleDbConnection(connectionPath2); OleDbCommand command2 = new OleDbCommand(@"SELECT * FROM Sales", conn2); OleDbDataReader reader2 = command2.ExecuteReader();
What I cannot do is execute my join statement:
//How do I do this? OleDbConnection connMagic = new OleDbConnection(connectionPath1, connectionPath2); //non-valid code OleDbCommand commandIWant = new OleDbCommand(@"SELECT Customers.Name, Sales.Item, Sales.Date FROM Customers LEFT JOIN Sales ON (Customers.ID=Sales.CustomerID)", connMagic); OleDbDataReader reader3 = commandIWant.ExecuteReader();
source share