Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error converting datetime to string

Tags:

c#

asp.net-3.5

I am getting an error when I attempt to display a datetime value in a textbox:

My code is:

txtStartDate.Text = rdrGetUserInfo.IsDBNull(14) ? String.Empty : Convert.ToString(rdrGetUserInfo.GetString(14));

The error message is: ex.Message = "Unable to cast object of type 'System.DateTime' to type 'System.String'."

Any ideas how I can resolve this?

like image 513
user279521 Avatar asked Mar 24 '10 15:03

user279521


1 Answers

Try:

txtStartDate.Text = rdrGetUserInfo.IsDBNull(14) ? String.Empty : Convert.ToString(rdrGetUserInfo.GetDateTime(14).ToString());
like image 190
Leniel Maccaferri Avatar answered Oct 08 '22 23:10

Leniel Maccaferri