Home » excel » Import Excel sheet into SQL Server through file upload in asp.net

Import Excel sheet into SQL Server through file upload in asp.net

Posted by: admin April 23, 2020 Leave a comment

Questions:

I am designing for a requirement which would provide user with an asp.net upload control to upload excel file(xls/xlsx/any advanced format) and load this excel data to SQL server 2008 data table with custom column mapping.

On internet I have found many blogs to implement this functionality using Jet OLEDB provider but there are some limitation to this functionality as below –

  1. The data is truncated for the data after first few rows in the table – Reasone is Jet provider checks initial few rows to decide on the data type and its size. Resolution that I found for this is go to Registry and change the value for “TypeGuessRows”. My question is – Is this advisable to do this on the web server in case of asp.net application

  2. Unicode characters does not get imported correctly – This issue can be resolved by changing the connection string to add “CharacterSet=65001;” as per link UnicodeCharacters

Again question is whether this would be advisable and full proof solution.

What is the best way to implement Import Excel to SQL Server 2008 for huge data intensive excel to be imported to Database without loosing any data and unicode characters?? The solution should be compatible with Excel 2003/2007/2010/2013.

How to&Answers:

I use this library to import xlsx files after upload.

https://exceldatareader.codeplex.com/

Does this help?

Answer:

You could help you. https://freenetexcel.codeplex.com

 Workbook workbook = new Workbook();

 workbook.LoadFromFile(@"..\..\parts.xls",ExcelVersion.Version97to2003);
 //Initialize worksheet
 Worksheet sheet = workbook.Worksheets[0];

 DataTable dataTable = sheet.ExportDataTable();