简体   繁体   English

从SQL到vb.net datetimepciker的检索日期值大于2030时出现问题

[英]Issue when retrieved date value is greater than 2030 from SQL to vb.net datetimepciker

Retrieving Date value from sql into datetimepicker in Vb.Net form using sql data table. 使用sql数据表以Vb.Net格式从sql检索Date值到datetimepicker For dates with year 2030 or more, value is displayed as 1930 in datetime picker. 对于年份为2030或更长的日期, datetime选择器中的值显示为1930。 Please help in solving this issue. 请帮助解决此问题。

Code to retrieve value: 检索值的代码:

dtpDate.Value = sqlDT.Rows(i)("StartDate").ToString dtpDate.Value = sqlDT.Rows(i)(“ StartDate”)。ToString

For example, 例如,

If retrieved value of sqlDT.Rows(i)("StartDate").ToString is'10/30/2032' then dtpDate value is displayed as '10/30/1932'. 如果检索到的sqlDT.Rows(i)(“ StartDate”)。ToString的值为'10 / 30/2032',则dtpDate值将显示为'10 / 30/1932'。

This code is working fine for all the dates till 2030 year . 该代码对于直到2030 year所有日期都适用。

DataTimePicker.Value is of type Date . DataTimePicker.Value的类型为Date

You should give value of correct type 您应该提供正确类型的值

dtpDate.Value = sqlDT.Rows(i).Field(Of Date)("StartDate")

When working with vb.net you should set "Option Strict" setting to On in project settings or locally for the file writing Option Strict On on the first line of file. 当vb.net工作,你应该设置“选项严格”设置On项目设置,或在本地的文件写入Option Strict On对文件的第一行。

In your case with Option Strict On you get compile error "String can not be converted to Date", which possible saves your time. 如果您使用Option Strict On则会出现编译错误“无法将字符串转换为日期”,这可以节省您的时间。

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

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