Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

can any help me in getting data from Ms Access Database
i am using OleDbDataReader to get data in reader object. In database the date value shows is 28-Jan-2034 . But when when i set this value to a date Time picker control the year changes to 1934.

using this code.

C#
dateTimePicker_chq_dt.Text = "" + DateTime.(RDR[5].ToString()).ToShortDateString();



the problem is in reader object. i tried to get parts of date value like day,yr and month separately that even doesn't work.

C#
int YR = DateTime.Parse(RDR[6].ToString()).Year;
           int Mn = DateTime.Parse(RDR[6].ToString()).Month;
           int Dy = DateTime.Parse(RDR[6].ToString()).Day;

           dateTimePicker_mature_dt.Value = new DateTime(YR, Mn, Dy);




Can any one suggest me any solution.
Posted

You cannot extract the different parts after converting the DateTime value to a String. Use the properties of the object as described in https://msdn.microsoft.com/en-us/library/system.datetime%28v=vs.110%29.aspx[^].
 
Share this answer
 
Comments
aarif moh shaikh 22-Apr-15 5:07am    
agree with you...
try this
DateTime d = new DateTime(YR, Mn, Dy);
dateTimePicker_mature_dt.Value =d.toString("d MMM yyyy") 
 
Share this answer
 
Thank you for your solutions, but the main problem is the change of date from DB to UI in DB its 12-Jan-2034 and while showing it on UI its changes to 12-Jan-1934.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900