Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I'm trying to create a small application to get data from database and export it to excel.

I want to compare input file Excel (one or more columns will be in excel) and compare same columns in database and return matched data and export it to excel.

For example if excel file has Columns: Account,Account Id

Database may have columns : Account,Account Id, Name,Address

process should compare Account and Account ID then return Name and Address for all the records.

Also file may contain huge data (2 to 3Gd ).

Please advise how to compare and extract data to excel.



Regards,
harish
Posted

1 solution

What's the problem?

Have a read this: Accessing Microsoft Office Data from .NET Applications[^]
As you can see, you can access MS Excel data using ADO.NET (OleDb) provider. What it meant to you?
You can compare data using
  1. single sql command with OPENROWSET[^] or OPENDATASOURCE[^] command. For example, if you want equal data, use this:
    SQL
    SELECT a.Field1, a.Field2
    FROM dbo.TableName as A INNER JOIN (
    SELECT *
     FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
      'Excel 8.0;Database=C:\excel-sql-server.xls', [Sheet1$])) AS b ON a.ID = b.ID

    More examples: The Basics of Excel Data Import to SQL Server[^]
  2. linq[^]. How? Load from Excel and SQL server into separate datatables[^]. Convert it to IEnumerable/IQuerable objects[^] and compare using linq query.
 
Share this answer
 
Comments
harishgajawada 22-Jan-14 13:11pm    
Thanks for the reply. i'm new to asp.net and i was not aware of this.

Once again thanks for the Help.
Maciej Los 22-Jan-14 13:12pm    
You're welcome ;)
harishgajawada 23-Jan-14 11:21am    
Maciej Los,

Please help me on below.

if i fill data table with excel data ,then can i pass datatable values in sql query like (select * from database.table where account in(select * from datatable))?

plesae advise.


Maciej Los 24-Jan-14 2:52am    
Using T-SQL - you can't. Using Linq - you can ;)
harishgajawada 14-Feb-14 13:12pm    
Hi Maciej Los,

I'm Using blelow as sql command and i'm getting ora-00907: missing right parenthesis.
i searched online and found that it is related to some missing "'" etc. i looked at the query and its is correctly formattted. can you please advice what i'm missing in below. i'm using "OleDb" to connect to oracle and fill the datatable.


SELECT CONCAT ( AL1.B_CD, AL1.A_CD ) as ac AL1.NA_LINE_TXT FROM table1.na AL1 right join ( select * from openrowset('Provider=Microsoft.ACE.OLEDB.12.0';Data Source='C:\Harish\New Microsoft Office Excel Worksheet.xlsx';Extended Properties="Excel 12.0;HDR=Yes;IMEX=2",[Sheet1$])) as b on ac=b.ac

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