C# .NET - Too many fields defined exception while importing excel data

Asked By U on 28-Jul-11 08:12 AM
The below exception was caught while importing excel data into application.Two worksheets are available in the excel file,first worksheet data gets imported properly into a Dataset,but second worksheet data doesn't,exception was caught at

dataAdapter.Fill(dsData); line in below Lines of Code.

strSQL = "SELECT * FROM [" + sheetName + "$]";

dbCommand = new OleDbCommand(strSQL, excelConnection);

dataAdapter = new OleDbDataAdapter(dbCommand);

dataAdapter.Fill(dsData);





Exception Description:

System.Data.OleDb.OleDbException was caught
  Message="Too many fields defined."
  Source="Microsoft JET Database Engine"
  ErrorCode=-2147467259
  StackTrace:
   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, String 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 ImportData.ReadExcelFile(String filePath)
  InnerException:

Please do the needfull,any help is appreciated and thankful.
Riley K replied to U on 28-Jul-11 08:22 AM
In your connection string First, change HDR=YES to HDR=NO... if you mentioned

Try putting the column names from which you want data in the select statement, based on the column headers from Row 1 of your excel worksheet.
Peter Bromberg replied to U on 28-Jul-11 08:46 AM
How many fields are there? You may just have too many for the provider.