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

时间:2017-10-12 09:45:37

标签: sql sql-server vb.net datetimepicker

Retrieving Date value from sql into datetimepicker in Vb.Net form using sql data table. For dates with year 2030 or more, value is displayed as 1930 in datetime picker. Please help in solving this issue.

Code to retrieve value:

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'.

This code is working fine for all the dates till 2030 year.

1 个答案:

答案 0 :(得分:0)

DataTimePicker.Value的类型为Date

您应该给出正确类型的值

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

使用vb.net时,您应该设置" Option Strict"在项目设置中设置为On,或在文件的第一行设置文件Option Strict On

Option Strict On的情况下,您会收到编译错误" String无法转换为Date",这可以节省您的时间。