tags:

views:

19

answers:

1

currently I am having sucsess with reading the excel file with my c# ,net 2 winform application. All works well with string and numerical types, but when it comes to date columns it still casts them as string.

I have read that ado.net scans the first eight rows and then uses that to determine the datatype...I have extended my test file to include more than eight rows - but I still have the same results.

thanks for any help you can provide

DataTable tbl = new DataTable();
  OleDbConnection dbConnection =
    new OleDbConnection (@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test.xls;Extended Properties=""Excel 8.0;HDR=Yes;""");
  dbConnection.Open();
  try
  {
    OleDbDataAdapter dbAdapter =  new OleDbDataAdapter("SELECT * FROM [Sheet1$]", dbConnection);
    dbAdapter.Fill(tbl);
  }
  finally
  {
    dbConnection.Close();
  }

.net 2.0, c#, vs2008

+1  A: 

Is the field formatted as date in the excel file?

Giorgi
is that how it works? see this: http://blog.lab49.com/archives/196
fishhead