Advanced data bindings and DBNull

My project reads dates back from SQL Server and displayes then using a Details view. In some instances, two of the dates displayed are meaningless data, they only apply if another value is set.

Under DataBindings - Advanced, I notice you can set a NullValue to display in the event of a DBNull being returned.

Well, the fields are Null (at least according to the Show Data function in Database Explorer) but regardless of what I put in the box, today's date is always displayed when I run the application.

Rich

[536 byte] By [RichLeyshon] at [2007-12-24]
# 1

If you're using a DateTimePicker it will have to display some date value.

Since it's a calculated value (not one the user is to change directly) you can probably test for it being null on the BindingSource.CurrentChagned (or similar event) and hide the DateTimePicker if it is null.

rkimble at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

Didn't make myself too clear there, it is both a "calculated value" and also one which can be reset by the user.

Anyway, I made the date/time picker invisible and dropped a formatted textbox over the top of it to display data from the dataset. I then changed over the visibility to the date/time picker when the user clicked the textbox i.e. wanting to change the date.

Seems like the ideal solution!

Thanks, Rich

RichLeyshon at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

Perfect! Excatly what i would have suggested given the need to edit.

Good luck!

rkimble at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...