开发者

how do I read an xls file with datetime columns using OleDb

开发者 https://www.devze.com 2023-01-02 12:23 出处:网络
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 a

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 dbC开发者_如何学Connection =
    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


Is the field formatted as date in the excel file?

0

精彩评论

暂无评论...
验证码 换一张
取 消