简体   繁体   中英

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

DataTimePicker.Value is of type 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.

In your case with Option Strict On you get compile error "String can not be converted to Date", which possible saves your time.

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.

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