I have 100 excel files. In each file I need one row from it to be inserted into SQL server. I need this automated but ultimately don't care if it is asp.net in an app or excel macros. If you have any ideas, please let me know.
Issue I wrote the asp.net 4.0 command line app code then got the error: The 'Microsoft.Ace.OleDb.4.0' provider is not registered on the local machine.
Tried After I installed Microsoft Access Database Engine 2010 Redistributable, (http://www.microsoft.com/en-us/download/details.aspx?id=13255) there are no more odbc drivers on my box. Just the SQL drivers as before.
My box is x64 but I have x86 office installed so I installed the Microsoft Access Database Engine 2010 Redistributable for x86.
I also checked the registry and can't see any drivers but the SQL server drivers.
I've read several articles:
The 'Microsoft.ACE.OLEDB.12.0' provider is not registered in the local machine
While I'm going to include my code below, I don't think it makes a difference until I have the drivers -
public void ImportExcelFilesForPieChart()
{
List<DataTable> listDataTables = new List<DataTable>();
List<CompanyInfo> newlist = new List<CompanyInfo>();
string sheetName = "Output";
string[] fileList = Directory.GetFiles(dropBoxExcelLocation);
foreach (string filename in fileList)
{
DataTable dt = new DataTable();
string connectionString = string.Format("Provider=Microsoft.Ace.OleDb.4.0;data source={0};Extended Properties=Excel 8.0;HDR=No;IMEX=1", dropBoxExcelLocation + filename);
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
string strSQL = String.Format("SELECT 4A, 4B, 4C, 4D, 4E, 4F FROM [{0}$]", sheetName); //[A4:F4]";
OleDbCommand objCmd = new OleDbCommand(strSQL, connection);
connection.Open();
using (OleDbDataAdapter da = new OleDbDataAdapter(strSQL, connection))
{
da.Fill(dt);
listDataTables.Add(dt);
}
}
}
}