I\'ve got a DateTime? that I\'m trying to insert into a field using a DbParameter. I\'m creating the parameter like so:
DbParameter
If you're using C# 3.0 you can create an extension method to do this easy:
public static class DBNullableExtensions
{
public static object ToDBValue(this Nullable value) where T:struct
{
return value.HasValue ? (object)value.Value : DBNull.Value;
}
}
class Program
{
static void Main(string[] args)
{
int? x = null;
Console.WriteLine( x.ToDBValue() == DBNull.Value );
}
}