开发者

Error converting datetime to string

开发者 https://www.devze.com 2022-12-23 20:11 出处:网络
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(

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.Mes开发者_如何学编程sage = "Unable to cast object of type 'System.DateTime' to type 'System.String'."

Any ideas how I can resolve this?


Try:

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

精彩评论

暂无评论...
验证码 换一张
取 消