Ion Ion - 1 year ago 76
C# Question

read from 2 dbf files in different foldes

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);
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());


If i try with only 1 table Works fine, so the problem is how to join2 tables in different folders?

Answer Source

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);

    t.Load( cmd.ExecuteReader() );
// t has yopur data