0

I've 2 excel sheets. One has the asset mapping (assets tagged to each employee) & the other has the organization head count (employee ID & the Name of all the valid employees). Now I want to check whether all the assets are tagged to a proper associate (i.e., employees tagged to a asset should be currently working in the organization), if not, I need to get the details of assets that are tagged to invalid users. For this I need to have a join condition from the 2 excel sheets & should load the result to a datatable (which I can latter show in a datagrid view or use to compose a mail to senior leadership).

So, I want to load the datatable from these 2 excel sources, with below similar query,

select a.[Asset ID], a.[EmpNo] from [AssetMapping$] as a 
Where a.[EmpNo] Not IN (select b.[EmpID] from [EmployeeDetails$] as b)

However I am not able to refer two excel sheets while loading data to a datatable (but I can do so if the data are present in two different sheets within same excel, which is not I am looking for).

Kindly help me in getting the required data from 2 different excel sheets to a single datatable.

Thanks in advance.

2
  • I think a way is to manually add rows and content to the datatable using a loop reading from the sources Commented Dec 27, 2013 at 8:54
  • @Allan Thanks a lot for your suggestion. However my data is quite huge & I don't want to have any manual work other then referring the 2 excel sheet paths. Also even if we use loop, how can I get the data from 2 different sources..? Is there any other way, where I can accomplish task in Vb.Net? Commented Dec 27, 2013 at 9:05

1 Answer 1

1

If you use OledDb providers (MS Jet database engine), try to use IN statement.

select a.[Asset ID], a.[EmpNo]
from [AssetMapping$] as a
Where a.[EmpNo] Not IN (select b.[EmpID] from [EmployeeDetails$] IN 'C:\Data\SecondWorkbook.xls' 'Excel 8.0;' as b)

For further information, please see: How To Use ADO.NET to Retrieve and Modify Records in an Excel Workbook With Visual Basic .NET

I hope it will helps.

See my article on CodeProject: http://www.codeproject.com/Tips/702769/How-to-Get-data-from-mulitple-Workbooks-using-one

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your valuable sugestion. However I did tried & its giving me a syntax error.. Syntax error. in query expression 'a.[EmpNo] Not IN (select b.[EmpID] from [EmployeeDetails$] IN 'C:\Data\SecondWorkbook.xls' 'Excel 8.0;' as b)'. Source=Microsoft JET Database Engine Is there anything else I am missing to add?
A special thanks to you.. Your suggestion has helped me in getting the required result. The earlier syntax error was due to usage of single quotes instead of double quotes, select [Asset ID], [EmpNo] from [Sheet1$] Where [EmpNo] Not IN (SELECT [EmpID] FROM [EmployeeDetails$] IN "C:\Data\SecondWorkbook.xls" "EXCEL 8.0;") The above query is working perfectly fine & its what I am looking for.
I'm glad you've found solution ;) Could you be so nice to vote-up my answer?
Unfortunately I am a newbie to this site & I don't have enough reputation to vote-up. Once I get enough reputation I will make sure to vote-up for your valuable solution.
I'm newbie too... Thank you very much ;)

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.