Last post Feb 21, 2013 05:34 AM by Pengzhen Song - MSFT
Feb 20, 2013 09:47 AM|Khalid Khan|LINK
can some one plz help me with how to read from an excel sheet if i dont know the headers of the columns on the excel sheet.
infact there are no proper column headers.
any help would be appreciated.
here is my code which reads some columns correctly and others dont. and often reads in irregular manner.
OleDbConnection oconn = new OleDbConnection
(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
(@"C:\" + file_name + ".xls ") +
";Extended Properties=Excel 8.0");
OleDbCommand ocmd = new OleDbCommand("select * from [Sheet1$]", oconn);
string data = "";
string test = "";
DateTime dt = Convert.ToDateTime("1-1-2001");
int i = 0;
//int j = 0;
OleDbDataReader rdr = ocmd.ExecuteReader();
int count = rdr.FieldCount;
for (int j = 0; j < count; j++)
data = Convert.ToString((rdr.GetValue(j)));
//j = 0;
Feb 21, 2013 12:43 AM|ToughMan|LINK
Use OleDbDataAdapter.Fill into a DataTable.
Feb 21, 2013 05:34 AM|Pengzhen Song - MSFT|LINK
If you specified HDR=YES in connection string, that indicates the result contains header rows.
Please refer here
Hope it can help you.