none
Storing Datetime in Ms. Access causing error RRS feed

  • Question

  • Hi,

    I am facing a strange problem. I have a datetimepicker in my screen. I have a textbox for user to enter DAYS and depends on this days, I need to add the days to the current date and get the new calculated date and store in the Ms. Access database. 

    The issue is....if the new calculated date is "13/12/2012 12:00:00 PM"...this will store correctly in database "13/12/2012 12:00:00 PM"  but

                          if  the new calculated date is "11/12/2012 12:00:00 PM"...this will store as "12/11/2012 12:00:00 PM"

    why is this happening. I really could not figure out where is the issue.

    Kindly help me.

    Thanks

    Malini

    Friday, September 14, 2012 6:02 PM

Answers

All replies

  • Show your code. Most likely you did not store date time as date time and mixed different culture somewhere in your string operation.


    Visual C++ MVP

    Friday, September 14, 2012 9:37 PM
  • Hi Sheng,

    Thanks . here is my code 

    DateTimePicker1.Value = Now.AddDays(Convert.ToInt32(txtNoOfDays.Text))

     cmd2 = New OleDbCommand("Update DW_Users set PasswordExpiryDate=#" + IIf(lblNextPwdExpiryDate.Text.Trim = String.Empty, defaultDate, DateTimePicker1.Value.Date.ToString("dd/MM/yyyy hh:mm:ss")) + "# where ID=" & Me.txtUserID.SelectedValue & "", conn)

    Highly appreciate

    Malini

    • Marked as answer by lini0103 Sunday, September 16, 2012 8:21 AM
    • Unmarked as answer by lini0103 Sunday, September 16, 2012 8:22 AM
    Saturday, September 15, 2012 2:59 AM
  • Try use DateTime.TryParse with the desired culture to get a date time, then pass the date time to a parameterized query, instead of passing text and let the database to decide the culture. 

    For how to set parameters for an ADO.Net command, search in http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/threads



    Visual C++ MVP


    • Edited by Sheng Jiang 蒋晟 Saturday, September 15, 2012 4:25 AM
    • Marked as answer by lini0103 Sunday, September 16, 2012 8:22 AM
    Saturday, September 15, 2012 4:25 AM
  • Hi Sheng,

    Thanks a lot, Paremeterized query helped me to solve the problem. Thanks again

    Malini

    Sunday, September 16, 2012 8:22 AM