phadaphunk phadaphunk - 1 year ago 76
SQL Question

Set an empty DateTime variable

I would declare an empty String variable like this:

string myString = string.Empty;

Is there an equivalent for a 'DateTime' variable ?

Update :

The problem is I use this 'DateTime' as a parameter for a 'StoredProcedure' in SQL.

DateTime? someDate = null;
myCommand.Parameters.AddWithValue("@SurgeryDate", someDate);

When I run this code an exception is catched telling me the 'StoredProcedure' expected a '@SurgeryDate' parameter.
But i provided it.
Any idea why?

Answer Source

Since DateTime is a value type you cannot assign null to it, but exactly for these cases (absence of a value) Nullable<T> was introduced - use a nullable DateTime instead:

DateTime? myTime = null;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download