Possible Duplicate:
DateTime.TryParse century control C#
I have a C# app that’s importing data from a .DBF file, and inserts it into SQL Server. There’s a DOB column in the file with the dreaded MM/dd/yy format. I just use the Convert.ToDateTime, and most data converts to the 1900’s like I expected it to. There are a handful of records that don’t convert correctly and have people born 30 years from now. How do I force the conversion to only write MM/dd/19XX?
So for example this date in the .DBF file 12/29/29 gets converted to 12/29/2029.
I’m reading the .DBF file like so:
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;
You can change the Calendar.TwoDigitYearMax property to change the last year of the 100 year range.