简体   繁体   English

时间格式更改错误 - GridDataView / VBnet

[英]Error on time format change - GridDataView / VBnet

I am storing in SQL HH:mm:ss format ( time(2) ), and GridDataView shows it this way.我以 SQL HH:mm:ss 格式( time(2) )存储,GridDataView 以这种方式显示。 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颜色变化很好,但值不可见 - 显示 ExceptionError - 输入格式不正确DataGridView 默认错误

That SQL Server data type should map to TimeSpan in .NET.该 SQL Server 数据类型应映射到 .NET 中的TimeSpan "HH:mm" is a valid format specifier for DateTime but not for TimeSpan . "HH:mm" 是DateTime的有效格式说明符,但不适用于TimeSpan TimeSpan didn't even support formatting before .NET 4.0 and, since then, you'd need to use "HH\\:mm", escaping the delimiter. TimeSpan在 .NET 4.0 之前甚至不支持格式化,从那时起,您需要使用“HH\\:mm”来转义分隔符。 Read more about formatting TimeSpan values here . 在此处阅读有关格式化TimeSpan值的更多信息。

更改为经典 Datetime 对象解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM