Jump to content
Xtreme .Net Talk

Object of type 'System.DBNull' cannot be converted to type 'System.Nullable` 1[System


Recommended Posts

Posted

So if DateTime is suppose to be Nullable in 2.0 why do I get this error (nullable value types is suppose to be something support in 2.0 I believe)?

 

Basically I have a form where I'm updating the date, the date can be null in the database if it's not used, meaning I must be able to set the field to null from the front end application.

 

Basically what I'm doing in my DataList is if the text box that represents the Date is blank, I don't set the Update Parameter. I have tried the 'ConvertEmptyStringToNull' property to both true and false, both get the same errors.

 

I hate to have to do a bunch of special if statements looking for DateTime.MinValue - but if I have to do it so be it. But now in my stored procedure I have to look for that value and set the value manually to null in the stored procedure; which is just plain bad.

 

Any help would be appreciated.

Posted

So the answer to this one is that the ObjectDataSource has a propert called ConvertNullToDBNull - you need to set this to false which is kind of non-intuitive - to me at least. What's it saying behind the scenes is that whenever you have a null value for a parameter it's going to being passing DBNull to the underlying business object - in my case a DataSet/TableAdapter. The TableAdapter parameter has the System.Nullable structure (or whatever you want to call it) but apparently DBNull isn't one of those.

 

It's weird, I can't fully explain it yet but this was the work around.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...