Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

Can any one please advice what is the best way to compare excel data with data in Oracle and return matching information using c#?

I can create a temp table in oracle database, upload excel data to table and run query to compare data in temp table with actual table and get data.

But let me know if it can be done in any other way.

Ex: I have excel data with vehicle numbers and Oracle has details of vehicles, owner name & address.
I want to get all the information which match vehicle numbers in excel.

please let me know best to do this. Also if you can provide sample code it would be great.

Thanks in Advance.
Posted

1 solution

If you want to do it in c# you can do it in this fashion.

1. Get the relevant columns from Oracle into DataTable dtOracle
Populating a DataSet from a DataAdapter[^]
(The same appraoch can be used for a DataTable as well)

2. Get the relevant columns from Excel into DataTable dtExcel
For this you can use OleDb.
Reading and Writing Excel using OLEDB[^]
Excel connection strings[^]

3. Then you implement a method to find the matching columns
3a. Loop through all rows in dtExcel and check if the vehicle number exists in dtOracle.
This sample is pretty straight forward, however not very efficient
C#
foreach (DataRow drExcel in dtExcel.Rows)
{
    DataRow drOracle = dtOracle.Select(String.Format("vehicle_number = '{0}'", drExcel ["vehicle_number"])).FirstOrDefualt();
    if (drOracle != null)
    {
        // Well, what to do here is up to you
    }
}

3b. Use LINQ to do the job.
Queries in LINQ to DataSet[^]
C# - using LINQ to Query DataTable[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900