locked
Insert date and time in to oracle from VB.NET RRS feed

  • Question

  • User-1578974752 posted

    I am having issue while inserting Date and Time in to oracle database. When I used date ,it is working but when I added time it is not working.Appreciate the Help

      dissue.Text = System.DateTime.Now.ToString("dd/MMM/yyyy")

    I paced the dissue.Text  in the insert statement and working fine.but

    dissue.Text = System.DateTime.Now.ToString("MM/DD/YYYY HH:MM:SS")  -> Not working

    Thursday, December 6, 2018 2:23 AM

Answers

  • User61956409 posted

    Hi shsu,

    shsu

    having issue while inserting Date and Time in to oracle database. When I used date ,it is working but when I added time it is not working.

    To troubleshoot the issue, you can debug your code and check the actual SQL query of inserting data, and then you can execute that SQL query in your database which would show you detailed exceptions. Perhaps a invalid value are passed and inserted, which cause the issue.

    Besides, you an check this article to know about "Insert a date/time value into an Oracle table".

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 7, 2018 7:24 AM

All replies

  • User1623409651 posted

    Hi,

    Try the below code 

    dissue.Text = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt")

    Refer the below article for more details

    https://www.codeproject.com/Articles/1098148/How-to-Insert-a-DateTime-Value-into-an-Oracle-Tabl

    Hope it helps

    Thursday, December 6, 2018 4:35 AM
  • User753101303 posted

    Hi,

    You also changed the date format in addition to adding the time ??? Decide first which country convention you want to use. You could use https://docs.microsoft.com/en-us/previous-versions/bz9tc508(v=vs.140) to select the needed culture rather than hardcoding date formats in your code.

    When  sending back dissue.Text to Oracle, this value should be converted back to a DateTime and used to feed a SQL parameter. This way your app should work without having to take care about handling a particular format (and potentially could work as well if you want later to suppot some other language using a different convention for date values).

    Thursday, December 6, 2018 12:37 PM
  • User61956409 posted

    Hi shsu,

    shsu

    having issue while inserting Date and Time in to oracle database. When I used date ,it is working but when I added time it is not working.

    To troubleshoot the issue, you can debug your code and check the actual SQL query of inserting data, and then you can execute that SQL query in your database which would show you detailed exceptions. Perhaps a invalid value are passed and inserted, which cause the issue.

    Besides, you an check this article to know about "Insert a date/time value into an Oracle table".

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 7, 2018 7:24 AM