Click here to Skip to main content
15,888,024 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi
I have restarted developing in C# after quite some time. It's like i have taken a long break.

But anyway to get to the point, I have a situation where I need to upload the contents of an Excel file into SQL Server tables through a C# application that i am designing.

What would be the best approach?

I have shortlisted the following methods

1. Excel Interop
2. convert the excel file to csv
3. convert the excel file to xml
4. OLE DB

Questions
1. What would be the recommended approach and why?
2. How can i check using any of the above whether the source Excel file is in the right format (missing columns, header missing etc). I want just a general guideline you might say.
3. Are the above methods (1-4) correct? is there any other method i have missed out?

Any responses are welcome

thanks a ton in advance
Posted
Comments
Cueen 8-Jan-16 7:29am    
Bashir gave some nice point, especially the one regarding the OLEDB. This approach is much faster then Excel Interop however you're unable to do the missing columns, header missing, etc. checks with it.
Nevertheless here is another approach that is much much faster then Excel Interop which uses this C# component for excel files. It can directly export an excel's sheet (or a part of it) into a DataTable with C#.

1 solution

Hi.
1. Better use to create rich formatting for new documents. Not very useful for read-only purposes.
2. Fast enough, but requires additional conversion and verification.
3. Fast enough, but requires additional conversion and verification.
4. Personally for me this is the best choice for read-only tasks. It is very quick (thousand times comparatively to Interop)
 
Share this answer
 
Comments
RebornDeveloper 26-Jul-10 11:53am    
Hi
Thanks a lot for your very useful comments

RD

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