Hello,
I am using Databinding to bring values from an SQL Server DB through onto my form.
The code is :
This works well in most cases, but as I have a couple of DateTimePickers on my form aswell, and these don't work so well.
Basically they are fine as long as there isn't a null value in the Database.
If one of the Date fields is null (i.e. Date Of Birth), then I get thrown an error of :
"Object cannot be cast from DBNull to other types."
What is the best way to resolve this ? (Apart from ensure there are no Null fields in the DB, as this isn't possible at the moment.)
I'd be happy for the DateTimePickers to be populated with a default date or be blank, whichever is easier really.
Thanks,
J.
I am using Databinding to bring values from an SQL Server DB through onto my form.
The code is :
Code:
txtName.DataBindings.Clear()
txtName.DataBindings.Add("Text", ds.Tables(0), "Name")
This works well in most cases, but as I have a couple of DateTimePickers on my form aswell, and these don't work so well.
Basically they are fine as long as there isn't a null value in the Database.
If one of the Date fields is null (i.e. Date Of Birth), then I get thrown an error of :
"Object cannot be cast from DBNull to other types."
What is the best way to resolve this ? (Apart from ensure there are no Null fields in the DB, as this isn't possible at the moment.)
I'd be happy for the DateTimePickers to be populated with a default date or be blank, whichever is easier really.
Thanks,
J.