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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble Querying Excel File with C#

Status
Not open for further replies.
Mar 9, 2006
93
CA
I have a program that opens an excel sheet and selects all the data from the sheet and then loads it into a DataTable.
The problem is that it skips the first row an loads the rest of data. Here is my code.

conn = new OleDbConnection(sConnectionString);
conn.Open();
OleDbCommand cmd =new OleDbCommand(statement, conn);

OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
dt = new DataTable();
conn.Close();
da.Fill(dt);

Thanks
Matt
 
Hi Matt,

Are the column names within your new table, the values from the first row of data that you are missing? I've not used OleDbDataAdapter but I have seen this behaviour in MS Access when loading data into a new table.
I would try defining the columns of the new table before filling it. Otherwise there may be a flag which needs to be set.

Cheers
MJ
 
I am trying just to read in the Data and store it in a DataTable. From here I just want to insert this data into SQLServer database. In the excel sheet there are no headings in the first column.
Thanks
Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top