This project is read-only.

Please support Null Dates

Jan 16, 2009 at 9:25 PM

I have a suggested update, with sample code.  Some of the date fields in the test DBF I'm working with are empty.  The following updates seem to handle this.

Chris Hankey


CProgram.Main()

 

if (orec.GetDateValue(i).HasValue == true)

 

{

swcsv.Write(orec.GetDateValue(i).Value.ToString(

"MM-dd-yyyy"));

 

}



DBFRecord.cs
public Nullable<DateTime> GetDateValue(int nColIndex)

 

{

 

DbfColumn ocol = mHeader[nColIndex];

 

 

if (ocol.ColumnType == DbfColumn.DbfColumnType.Date)

 

{

 

string sDateVal = ASCIIEncoder.GetString(mData, ocol.DataAddress, ocol.Length);

 

 

try

 

 

 

{

 

return DateTime.ParseExact(sDateVal, "yyyyMMdd", CultureInfo.InvariantCulture);

 

}

 

catch

 

 

 

{

 

return null;

 

}

}

 

else

 

 

 

 

throw new Exception("Invalid data type. Column '" + ocol.Name + "' is not a date column.");

 

 

}