Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
11
Answers
Object cannot be cast from DBNull to other types (Date)
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Chriz L
9y
606
1
Reply
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.
Post
Reset
Cancel
Answers (
11
)
Next Recommended Forum
Display multiple Images in datalist
how to add page title as well as click on link using html?