<分区> 分区>
Possible Duplicate:
DateTime.TryParse century control C#
我有一个 C# 应用程序,它从 .DBF 文件导入数据,并将其插入到 SQL Server 中。文件中有一个 DOB 列,格式是可怕的 MM/dd/yy。我只使用 Convert.ToDateTime,大多数数据都会像我预期的那样转换为 1900 年代。有一些记录没有正确转换,并且有 30 年后出生的人。如何强制转换为只写 MM/dd/19XX?
例如,.DBF 文件 12/29/29 中的这个日期被转换为 12/29/2029。
我正在像这样读取 .DBF 文件:
var fileInfo = new System.IO.FileInfo(dbfPath);
string dsPath = fileInfo.DirectoryName.ToString();
DataSet DSResult = new DataSet();
using (OleDbConnection cn = new OleDbConnection(
@"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data Source=" + dsPath + ";" + //Set the Data Sourde = to the directory of the file.
@"Extended Properties=dBASE III;"))
using (OleDbCommand cm = cn.CreateCommand())
{
cn.Open();
cm.CommandText = "SELECT * FROM UPDATED"; //Specify the file name for the select statement.
using (OleDbDataAdapter dba = new OleDbDataAdapter(cm))
{
dba.Fill(DSResult);
}
}
return DSResult;
