Click here to Skip to main content
11,702,396 members (70,544 online)

Eser Atesoglu asked:

Open original thread
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]
Tags: Excel, query, OleDb

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100