I insert into an Oracle DB Table using the following insert string (Approx — There’s 140 columns so I won’t show it all):
“INSERT INTO AMS_ASSET_CS_IFACEOUT VALUES ( ‘abcdef’, ‘abcdef’, to_date(‘2010-01-31’, ‘YYYY-MM-DD’), … )”
Then a couple of seconds later I run the following code snippet:
/// <summary>
/// Function: GetRecord
/// Description: Creates a new AMS-Asset and populates the
/// properties of this asset by evaluating properties provided
/// by the OracleDataReader.
/// </summary>
/// <param name="reader"> One record of information from the open connection.</param>
/// <returns> A fully created AMS-Asset record. </returns>
private static AmsAsset GetRecord(OracleDataReader reader)
{
AmsAsset newRecord = new AmsAsset();
for (int propertyIndex = 0; propertyIndex < reader.FieldCount; propertyIndex++)
{
string propertyName = reader.GetName(propertyIndex).ToLower();
string propertyValue = reader.GetValue(propertyIndex).ToString();
int propertyValueAsInteger = 0;
bool isPropertyAnInteger = Int32.TryParse(propertyValue, out propertyValueAsInteger);
if (isPropertyAnInteger)
{
newRecord.GetType().GetProperty(propertyName).SetValue(newRecord, propertyValueAsInteger, null);
}
else
{
newRecord.GetType().GetProperty(propertyName).SetValue(newRecord, propertyValue, null);
}
}
return newRecord;
}
The date value I inserted into my database is now returned as “1/31/2010 12:00:00 AM.”
I’m not entirely sure why… What are my options? Do I need to just code a conversion from the format I’m being given back into ISO
Regards,
Sean Anderson
Since you inserted into Database using an unambiguous ‘YYYY-MM-DD’ format date, it is correctly stored in database.
When you read it out and display that date, the format is dependent on your regional settings.
I suggest you use an explicit format specifier for displaying.