Click here to Skip to main content
15,885,983 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hello, I wrote app that read excel file, I used oledb and simple query like following

("select * from [Sheet1$]", MyConnection)

It's smoothly working but It defines first row of data from excel file as column name, so I have to insert datatable's column name at index 0 after retrieving data. but There is certain limit in naming DataTable column so it neglect some words exceeding that limit. How can I solve this problem.
Posted
Comments
NuttingCDEF 30-Apr-11 7:07am    
I'm not clear what the problem is. Can you post some code or an example of what you're getting / what you want / what's going wrong?
whitehaker 1-May-11 7:31am    
I mean Whenever I retrieve data from excel file, first row data is neglected.
I used following code..
System.Data.OleDb.OleDbConnection MyConnection ;
System.Data.DataSet DtSet ;
System.Data.OleDb.OleDbDataAdapter MyCommand ;
MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='mydata.xls';Extended Properties=Excel 8.0;");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
MyCommand.TableMappings.Add("Table", "excelData");
DtSet = new System.Data.DataSet();
MyCommand.Fill(DtSet);
MyConnection.Close();
-------------------------------------------------------
and if data to be read is as following table

1 | Book | 300 |
2 | Paper | 120 |
3 | Pen | 60 |
---------------------------

then data in dataset is lack of first row (1 | book | 300)
as these values are suggested as column name of table in dataset.

1 solution

You have probably messed up the HDR value in the connection string. It specifies that the first row is the table header or not.
 
Share this answer
 
Comments
whitehaker 1-May-11 7:20am    
Thanks alot for our answer.This really make me see

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900