Reputation: 355
How do I check if data existing in the database or is NULL. I'm getting the following error Object cannot be cast from DBNull to other types . Do I need to add IsDBNULL to the code?
SignedOn.Text = Convert.ToDateTime(reader("SignedOn")).ToShortDateString()
Upvotes: 0
Views: 470
Reputation: 63105
you can check like below
If NOT IsDbNull(reader("SignedOn")) Then
SignedOn.Text = Convert.ToDateTime(reader("SignedOn")).ToShortDateString()
End If
Edit based on comments:
reader.GetDateTime
, reader.GetString
etcToShortDateString
DateTime.TryParse
method if you have store date time in varchar columnUpvotes: 3