Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error reading Excel spreadsheet via OleDb

Status
Not open for further replies.

nwruiz

Programmer
Jun 22, 2005
60
US
Hello,

I am trying to use OleDb to extract information from an Excel spreadsheet I am downloaded from the Internet. The OleDbCommand command text I am using is here:

Code:
oleCmd.CommandText = "SELECT [MO], [DA], [YR], [S], [ ID], [T], [1/13], [2/14], [3/15], [4/16], " & _
                     "[5/17], [6/18], [7/19], [8/20], [9/21], [10/22], [11/23], [12/24], [25] " & _
                     "FROM [Sheet1$] " & _
                     "WHERE [MO] IS NOT NULL"

OleDb is using the first row of the spreadsheet as the "table" columns. Unfortunately, the creator of the spreadsheet named one of the columns "25." I am getting an exception in VB.NET, stating:

Code:
System.Data.OleDb.OleDbException occurred
  ErrorCode=-2147217904
  Message="No value given for one or more required parameters."
  Source="Microsoft JET Database Engine"
  StackTrace:
       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.ExecuteReader()
       at .......

I am certain that the problem is the "25" column. I tried eliminating that column from my select statement, which allowed the select statement to continue as normal.

Does anyone know how I can include the "25" column in my select query without raising an exception? Thank you for your help!

Nick Ruiz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top