C# .NET - import Excel 2010 in sql database table

Asked By Neeraj on 02-Apr-13 03:32 AM
I am developing an web application to import data from Excel 2010 to database table

DataTable dtExcel = new DataTable();

dtExcel.TableName = "MyExcelData";

string SourceConstr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='filepath';Extended Properties= 'Excel 8.0;HDR=Yes;IMEX=1'";

OleDbConnection con = new OleDbConnection(SourceConstr);

string query = "Select * from [Sheet1$]";

OleDbDataAdapter data = new OleDbDataAdapter(query, con);

data.Fill(dtExcel);


but i am getting error in thi line
OleDbDataAdapter data = new OleDbDataAdapter(query, con);

please suggest..
Danasegarane Arunachalam replied to Neeraj on 02-Apr-13 03:32 AM
This msdn article explains with details

How to import excel to SQL SERVER : http://code.msdn.microsoft.com/office/Imoprt-Data-from-Excel-to-705ecfcd
Neeraj replied to Danasegarane Arunachalam on 02-Apr-13 08:28 AM
getting this error in web aplication 

'microsoft.ace.oledb.12.0' provider is not registered on the local machine" 

on which server i am running this code office is not installed 
Danasegarane Arunachalam replied to Neeraj on 03-Apr-13 01:29 PM
There are two work arrounds

1. Change the target platform from anycpu to x86 in visual studio build option
2. Download and install the drivers from here - http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=23734
Sum Green replied to Neeraj on 03-Apr-13 09:11 PM
Hello,

Please have a look at this article: http://janewdaisy.wordpress.com/2011/11/29/c-export-data-from-excel-to-datatable/

I think that it may give you some suggestions.
abdul rehman replied to Neeraj on 08-Apr-13 08:31 AM
end of post