当我从 excel 导入数据集时,我的日期格式发生了变化
我的代码如下:
DataSet ds = new DataSet();
string myConnStr = "";
if (ds != null)
{
myConnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FilePath + "; " + "Extended Properties=\"Excel 12.0;HDR=YES\"";
}
else
{
myConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FilePath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"";
}
OleDbConnection myConn = new OleDbConnection(myConnStr);
try
{
OleDbCommand cmd = new OleDbCommand("select * from [Sheet1$] ",myConn);
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = cmd;
myConn.Open();
adapter.Fill(ds);
}
catch
{ }
finally
{
myConn.Close();
}
如果我从 excel 中逐行读取,那么我可以使用DateTime.FromOADate 在这里我不能这样做。请帮忙