Passing null to date/time field

  • Thread starter Thread starter Robert G
  • Start date Start date
R

Robert G

I am using MySql and create a new table that has a date/time field. I set
it to accept nulls as well.

Created a new XSD dataset in ASP.NET but I cannot set the NullValue property
to anything but "(Throw Exception)". (The DefaultValue property is
<DBNull>.)

I then created all of the typical class methods.

When I call the Insert method I tried passing system.dbnull.value but it
will not allow me to. It says that the type 'system.dbnull' cannot be
converted to 'date'.

2 Questions:
1. How can I change the NullValue property in my dataset to something other
than 'Throw Exception'?
2. How can I pass a null to my date/time field?

Thanks!
 
Robert G said:
I am using MySql and create a new table that has a date/time field. I set
it to accept nulls as well.

Created a new XSD dataset in ASP.NET but I cannot set the NullValue
property to anything but "(Throw Exception)". (The DefaultValue property
is <DBNull>.)

I then created all of the typical class methods.

When I call the Insert method I tried passing system.dbnull.value but it
will not allow me to. It says that the type 'system.dbnull' cannot be
converted to 'date'.

2 Questions:
1. How can I change the NullValue property in my dataset to something
other than 'Throw Exception'?
2. How can I pass a null to my date/time field?

Thanks!


You could do one of the following

private Nullable<DateTime> _yourDate;
private DateTime? _yourDate;


I hope this helps.
 
Do you have the vb.net version of that?

I tried this but it doesn't work...

Dim z As Nullable(Of DateTime)

ob.Insert(Request.QueryString("projectId"), z)


But I get this error: Nullable object must have a value.
 
I got it! Thanks.

In my CLASS I had to make sure that the args were set to Nullable(Of
DateTime).

Thanks!

Robert G said:
Do you have the vb.net version of that?

I tried this but it doesn't work...

Dim z As Nullable(Of DateTime)

ob.Insert(Request.QueryString("projectId"), z)


But I get this error: Nullable object must have a value.
 
Back
Top