views:

5

answers:

0

I have a method that gets the DateTime from the DB with the following code:

NpgsqlCommand cmd = ActiveConnection.CreateCommand(); cmd.CommandText = "SELECT NOW()";

object obj = cmd.ExecuteScalar(); return (DateTime)obj;

Sometimes an InvalidCastException is thrown when converting the result to DateTime. Sometimes the result (obj) is null. Any idea why this is happening? do you have any ideas on where to start scratching?

TIA José Tavares