1

I would like to ask if it is possible to retrieve a row of data from a INNER JOIN query from TWO different Excel files (example. excel1.xls, excel2.xls). I am using C# .net. and an OledbConnection.

Excel1.xls Column 1 BookID 1234 1515 2315

Excel2.xls Column 1 BookID 1234 1515 1100 1412 2215

Goal: I must retrieve only those rows in Excel1.xls that are included in Excel2.xls

Here's my code for the function: txtshowstopperpath.text = path of the Excel1.xls txtexcelpath.text = Path of the Excel2.xls

    sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={1};Extended Properties=Excel 12.0;";
    oConn = new OleDbConnection(sConnString);
oConn.Open();
sCommand = "SELECT * FROM [" + txtshowstopperpath.Text + "].[Sheet1$] A INNER JOIN [" + txtexcelpath.Text + "].[Sheet1$] B on A.[Book ID] = B.[Book ID]";       
oComm = new OleDbCommand(sCommand, oConn);
oRdr = oComm.ExecuteReader();
oTbl = new DataTable();
oTbl.Load(oRdr);
foreach (DataRow row in oTbl.Rows)
     {
         dgridshowrep.DataSource = oTbl;
    }
oConn.Close()

Thank you.

7
  • correction: rows of Data Commented Nov 25, 2017 at 9:19
  • Show examples of your data and format your code as code. Commented Nov 25, 2017 at 9:21
  • @RobAnthony - edited my post. sorry as this is my first time posting in this site. thank you Commented Nov 25, 2017 at 9:39
  • No, I don't believe you can. You will probably need to create two different data tables and the compare the data using some other method. Commented Nov 25, 2017 at 9:42
  • @MarkKram - thanks for your reply. Im stuck with this function. Commented Nov 25, 2017 at 9:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.