| View previous topic :: View next topic |
| Author |
Message |
manoj
Joined: 21 Aug 2007 Posts: 102
|
Posted: Wed Dec 30, 2009 11:35 am Post subject: Reading Excel spread sheet data problem in c# |
|
|
Hi,
I have an excel file with single column and 20 rows in a sheet. I am reading column data using connection string. But problem here is is returning 19 records even though 20 records exist. can any one let me know the solution for this problem asap.............
Here is my code :
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + serverPath + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";
OleDbConnection conExcel = new OleDbConnection(connectionString);
cmd = new OleDbCommand("select * from [Sheet1$]", conExcel);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds, "contacts");
foreach (DataRow dr in ds.Tables["contacts"].Rows)
{
}
please let me know the what might be the issue...
thanks & regards,
manoj |
|
| Back to top |
|
 |
craig
Joined: 24 Aug 2007 Posts: 36
|
Posted: Wed Dec 30, 2009 12:10 pm Post subject: |
|
|
Hi Manoj,
i too faced the similar issue. i solved with the following procedure. i.e in the connection string "HDR=Yes;" indicates that the first row contains columnnames, not data. "HDR=No;" indicates the opposite. try to replace "HDR=No;" instead. hope you will find the solution.
refer this link http://www.connectionstrings.com/excel-2007
regards
craig |
|
| Back to top |
|
 |
|