I am trying to créate a c# proyect to read data from 2 dbf tables(FoxPro), for this i need to do a JOIN, but i have a problem, the 2 files are in two different folders(1 in a folder and the other in a subfolder, this is what i try:
string Con = @"Provider=VFPOLEDB.1;Data Source=\\Srverp\gab";
OleDbConnection ConnectionHandler = new OleDbConnection(Con);
ConnectionHandler.Open();
OleDbDataAdapter DAT = new OleDbDataAdapter();
string SQL = @"SELECT * FROM bproved join .\ges_01\bproalb";
OleDbCommand Query = new OleDbCommand(SQL, ConnectionHandler);
OleDbDataReader datareader = Query.ExecuteReader();
while (datareader.Read())
{
Console.WriteLine( datareader.GetValue(0).ToString());
Console.ReadKey();
}
If i try with only 1 table Works fine, so the problem is how to join2 tables in different folders?
Simply use fullpath & filename enclosed in parentheses. ie:
string table1 = @"\\Srverp\gab\bproved.dbf";
string table2 = @"\\Srverp\gab\ges_01\bproalb.dbf";
string con = @"Provider=VFPOLEDB;Data Source=\\Srverp\gab";
string sql = string.Format(@"SELECT * FROM ('{0}') t1
inner join ('{1}') t2 on t1.bprovedId = t2.bprovedId",
table1, table2);
DataTable t = new DataTable();
using (OleDbConnection connectionHandler = new OleDbConnection(con))
{
OleDbCommand cmd = new OleDbCommand(sql, connectionHandler);
connectionHandler.Open();
t.Load( cmd.ExecuteReader() );
connectionHandler.Close();
}
// t has yopur data