I am storing in SQL HH:mm:ss format ( time(2) ), and GridDataView shows it this way. I am trying to change it both with Properties window, or by code
DataGridView1.Columns(5).DefaultCellStyle.BackColor = Color.Red
DataGridView1.Columns(5).DefaultCellStyle.Format = "HH:mm"
Color changes nicely, but value is not visible - shows ExceptionError - Incorrect Input Format DataGridView Default error
That SQL Server data type should map to TimeSpan
in .NET. "HH:mm" is a valid format specifier for DateTime
but not for TimeSpan
. TimeSpan
didn't even support formatting before .NET 4.0 and, since then, you'd need to use "HH\\:mm", escaping the delimiter. Read more about formatting TimeSpan
values here .
更改为经典 Datetime 对象解决了问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.