TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Chriz L
NA
220
51.1k
Object cannot be cast from DBNull to other types (Date)
Sep 30 2015 2:44 AM
Hello,
I retrieve data from db through dataset as following:
birthdate.Text = Convert.ToDateTime(ds.Tables[0].Rows[0]["BirthDate"]).ToString("dd/MM/yyyy");
My problem is when the BirthDate is null I get the following exception "
Object cannot be cast from DBNull to other types."
I tried:
if (String.IsNullOrEmpty(Convert.ToDateTime(ds.Tables[0].Rows[0]["BirthDate"]).ToString("dd/MM/yyyy").Trim()))
birthdate.Text = null;
else
birthdate.Text = Convert.ToDateTime(ds.Tables[0].Rows[0]["BirthDate"]).ToString("dd/MM/yyyy");
but I'm still getting the exception.
Any suggestions?
Thank you in advance.
Reply
Answers (
11
)
Display multiple Images in datalist
how to add page title as well as click on link using html?