Passing null to date/time field

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!
 
J

James Parker

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.
 
R

Robert G

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.
 
R

Robert G

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top