I am reading an excel spreadsheet in C# using OleDb connection. I get an error (See below) if any of the column headers in the excel is "Domain".
The error message is (raw)
System.Data.OleDb.OleDbException (0x80004005): IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, Strin
g srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at ExcelReader.Program.Main(String[] args) in C:\Users\Eser\Development\ExcelReader\ExcelReader\Program.cs:line 32
More message that I gathered from the Exception handling:
Message: IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
Native: -533136361
Source: IErrorInfo.GetSource failed with E_FAIL(0x80004005).
SQL: 3000
------------------------------------------------------------------
The c# statements are (not working!!!) and the excel column header contains "Domain":
OleDbCommand objCmdSelect = new OleDbCommand("SELECT DISTINCT * FROM [Sheet1$A1:F1228] WHERE Domain = 'Finance' AND Discipline = 'Taxation'", objConn);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
DataSet ds1 = new DataSet();
objAdapter1.Fill(ds1);
------------------------------------------------------------------
The c# statements are (working!!!) and the excel column header now contains "Domaine" or anything else (anything other than Domain):
OleDbCommand objCmdSelect = new OleDbCommand("SELECT DISTINCT * FROM [Sheet1$A1:F1228] WHERE Domaine = 'Finance' AND Discipline = 'Taxation'", objConn);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
DataSet ds1 = new DataSet();
objAdapter1.Fill(ds1);
Any suggestion/idea why this header keyword not being accepted by the query?
Eser
[edit]code blocks added[/edit]