Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Insert timestamp using datareader to oracle date

Insert timestamp using datareader to oracle date

Scheduled Pinned Locked Moved Visual Basic
databaseoracleregexhelptutorial
18 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kerek2
    wrote on last edited by
    #1

    Hi sir, I'm trying to insert datetime value from firebird database into oracle database but got "

    ORA-01861: literal does not match format string

    i'm using this command :

    oracmd.CommandText = "INSERT INTO ASIS.TIMECLOCK_DATA(TD_CARDHOLDER_ID,TD_EVENT_DATE) " & _
    " VALUES ('" + IBSSDR.Item("CARDHOLDERID").ToString + "',to_date('" + IBSSDR.Item("EVENTDATE") + "','YYYY-MM-DD HH24:MI:SS'))"
    '

    When i'm using this command

    oracmd.CommandText = "INSERT INTO ASIS.TIMECLOCK_DATA(TD_CARDHOLDER_ID,TD_EVENT_DATE) " & _
    " VALUES ('" + IBSSDR.Item("CARDHOLDERID").ToString + "',('" + IBSSDR.Item("EVENTDATE") + "'))"

    I got this error :-

    ORA-01843: not a valid month

    Please anyone can guide me? Plssss, tq

    Richard DeemingR V D 3 Replies Last reply
    0
    • K kerek2

      Hi sir, I'm trying to insert datetime value from firebird database into oracle database but got "

      ORA-01861: literal does not match format string

      i'm using this command :

      oracmd.CommandText = "INSERT INTO ASIS.TIMECLOCK_DATA(TD_CARDHOLDER_ID,TD_EVENT_DATE) " & _
      " VALUES ('" + IBSSDR.Item("CARDHOLDERID").ToString + "',to_date('" + IBSSDR.Item("EVENTDATE") + "','YYYY-MM-DD HH24:MI:SS'))"
      '

      When i'm using this command

      oracmd.CommandText = "INSERT INTO ASIS.TIMECLOCK_DATA(TD_CARDHOLDER_ID,TD_EVENT_DATE) " & _
      " VALUES ('" + IBSSDR.Item("CARDHOLDERID").ToString + "',('" + IBSSDR.Item("EVENTDATE") + "'))"

      I got this error :-

      ORA-01843: not a valid month

      Please anyone can guide me? Plssss, tq

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query. Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^] How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^] Query Parameterization Cheat Sheet | OWASP[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      • K kerek2

        Hi sir, I'm trying to insert datetime value from firebird database into oracle database but got "

        ORA-01861: literal does not match format string

        i'm using this command :

        oracmd.CommandText = "INSERT INTO ASIS.TIMECLOCK_DATA(TD_CARDHOLDER_ID,TD_EVENT_DATE) " & _
        " VALUES ('" + IBSSDR.Item("CARDHOLDERID").ToString + "',to_date('" + IBSSDR.Item("EVENTDATE") + "','YYYY-MM-DD HH24:MI:SS'))"
        '

        When i'm using this command

        oracmd.CommandText = "INSERT INTO ASIS.TIMECLOCK_DATA(TD_CARDHOLDER_ID,TD_EVENT_DATE) " & _
        " VALUES ('" + IBSSDR.Item("CARDHOLDERID").ToString + "',('" + IBSSDR.Item("EVENTDATE") + "'))"

        I got this error :-

        ORA-01843: not a valid month

        Please anyone can guide me? Plssss, tq

        V Offline
        V Offline
        Victor Nijegorodov
        wrote on last edited by
        #3

        Did you look at the debug/watch window to see how the SQl text contained in oracmd.CommandText looks like? Did you try to test this SQL expression in the Oracle DB?

        1 Reply Last reply
        0
        • K kerek2

          Hi sir, I'm trying to insert datetime value from firebird database into oracle database but got "

          ORA-01861: literal does not match format string

          i'm using this command :

          oracmd.CommandText = "INSERT INTO ASIS.TIMECLOCK_DATA(TD_CARDHOLDER_ID,TD_EVENT_DATE) " & _
          " VALUES ('" + IBSSDR.Item("CARDHOLDERID").ToString + "',to_date('" + IBSSDR.Item("EVENTDATE") + "','YYYY-MM-DD HH24:MI:SS'))"
          '

          When i'm using this command

          oracmd.CommandText = "INSERT INTO ASIS.TIMECLOCK_DATA(TD_CARDHOLDER_ID,TD_EVENT_DATE) " & _
          " VALUES ('" + IBSSDR.Item("CARDHOLDERID").ToString + "',('" + IBSSDR.Item("EVENTDATE") + "'))"

          I got this error :-

          ORA-01843: not a valid month

          Please anyone can guide me? Plssss, tq

          D Offline
          D Offline
          DerekT P
          wrote on last edited by
          #4

          I don't know Oracle so can only assume your date format string is correct; but:

          to_date('" + IBSSDR.Item("EVENTDATE") + "','YYYY-MM-DD HH24:MI:SS')

          is taking a (presumably) date object IBSSDR.Item("EventDate") and putting it directly into that function via string concatenation. As usual, put breakpoints in place and inspect the value of .CommandText - this will show you how VB has formatted that date field, using its default (local) formatting, as input to the function. You will most likely need to use some explicit formatting on the VB side to create a string that Oracle will be able to parse into a date. But, as Richard always says, don't build your SQL by string concatenation - parameterise it.

          K 2 Replies Last reply
          0
          • D DerekT P

            I don't know Oracle so can only assume your date format string is correct; but:

            to_date('" + IBSSDR.Item("EVENTDATE") + "','YYYY-MM-DD HH24:MI:SS')

            is taking a (presumably) date object IBSSDR.Item("EventDate") and putting it directly into that function via string concatenation. As usual, put breakpoints in place and inspect the value of .CommandText - this will show you how VB has formatted that date field, using its default (local) formatting, as input to the function. You will most likely need to use some explicit formatting on the VB side to create a string that Oracle will be able to parse into a date. But, as Richard always says, don't build your SQL by string concatenation - parameterise it.

            K Offline
            K Offline
            kerek2
            wrote on last edited by
            #5

            ooooo i get it, already try to other database like SQL db it can work... maybe oracle have restricted....thank you for idea

            1 Reply Last reply
            0
            • D DerekT P

              I don't know Oracle so can only assume your date format string is correct; but:

              to_date('" + IBSSDR.Item("EVENTDATE") + "','YYYY-MM-DD HH24:MI:SS')

              is taking a (presumably) date object IBSSDR.Item("EventDate") and putting it directly into that function via string concatenation. As usual, put breakpoints in place and inspect the value of .CommandText - this will show you how VB has formatted that date field, using its default (local) formatting, as input to the function. You will most likely need to use some explicit formatting on the VB side to create a string that Oracle will be able to parse into a date. But, as Richard always says, don't build your SQL by string concatenation - parameterise it.

              K Offline
              K Offline
              kerek2
              wrote on last edited by
              #6

              Ok sir thank for the idea it's done by this

              Dim touch As String = DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss tt")
              touch = ("" & IBSSDR.Item("EVENTDATE").ToString & "")

                                  oracmd.CommandText = "INSERT INTO ASIS.TIMECLOCK\_DATA(TD\_CARDHOLDER\_ID,TD\_EVENT\_DATE,TD\_FIRST\_IN,TD\_IN\_READER,TD\_IP\_CONTROLLER,TD\_TYPE) " & \_
                                                       " VALUES  ('" & IBSSDR.Item("CARDHOLDERID") & "',TO\_DATE('" & touch & "','dd/mm/yyyy hh:mi:ss am')," & \_
                                                      "TO\_DATE('" & touch & "','dd/mm/yyyy hh:mi:ss am'),'" & IBSSDR.Item("DEVICEID") & "','" & IBSSDR.Item("WINSOCKIPADDRESS") & "','CHECKIN') "
              

              Thank you for yuor help ;) ;)

              D D 2 Replies Last reply
              0
              • K kerek2

                Ok sir thank for the idea it's done by this

                Dim touch As String = DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss tt")
                touch = ("" & IBSSDR.Item("EVENTDATE").ToString & "")

                                    oracmd.CommandText = "INSERT INTO ASIS.TIMECLOCK\_DATA(TD\_CARDHOLDER\_ID,TD\_EVENT\_DATE,TD\_FIRST\_IN,TD\_IN\_READER,TD\_IP\_CONTROLLER,TD\_TYPE) " & \_
                                                         " VALUES  ('" & IBSSDR.Item("CARDHOLDERID") & "',TO\_DATE('" & touch & "','dd/mm/yyyy hh:mi:ss am')," & \_
                                                        "TO\_DATE('" & touch & "','dd/mm/yyyy hh:mi:ss am'),'" & IBSSDR.Item("DEVICEID") & "','" & IBSSDR.Item("WINSOCKIPADDRESS") & "','CHECKIN') "
                

                Thank you for yuor help ;) ;)

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                It may work now, but DO NOT get into the habit of using string concatenation to build SQL queries like you have. Google for "SQL Injection Attack" to find out why what you're doing is so bad. I refer you back to Re: Insert timestamp using datareader to oracle date - Visual Basic Discussion Boards[^]

                Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                Dave Kreskowiak

                K 2 Replies Last reply
                0
                • K kerek2

                  Ok sir thank for the idea it's done by this

                  Dim touch As String = DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss tt")
                  touch = ("" & IBSSDR.Item("EVENTDATE").ToString & "")

                                      oracmd.CommandText = "INSERT INTO ASIS.TIMECLOCK\_DATA(TD\_CARDHOLDER\_ID,TD\_EVENT\_DATE,TD\_FIRST\_IN,TD\_IN\_READER,TD\_IP\_CONTROLLER,TD\_TYPE) " & \_
                                                           " VALUES  ('" & IBSSDR.Item("CARDHOLDERID") & "',TO\_DATE('" & touch & "','dd/mm/yyyy hh:mi:ss am')," & \_
                                                          "TO\_DATE('" & touch & "','dd/mm/yyyy hh:mi:ss am'),'" & IBSSDR.Item("DEVICEID") & "','" & IBSSDR.Item("WINSOCKIPADDRESS") & "','CHECKIN') "
                  

                  Thank you for yuor help ;) ;)

                  D Offline
                  D Offline
                  DerekT P
                  wrote on last edited by
                  #8

                  As others have said, avoid string concatenation, use parameterised queries (which in this instance would also avoid all the date formatting). Your thanks and confirming you've got the code working is appreciated! :-)

                  K 1 Reply Last reply
                  0
                  • D DerekT P

                    As others have said, avoid string concatenation, use parameterised queries (which in this instance would also avoid all the date formatting). Your thanks and confirming you've got the code working is appreciated! :-)

                    K Offline
                    K Offline
                    kerek2
                    wrote on last edited by
                    #9

                    Thank you for advised. :)

                    1 Reply Last reply
                    0
                    • D Dave Kreskowiak

                      It may work now, but DO NOT get into the habit of using string concatenation to build SQL queries like you have. Google for "SQL Injection Attack" to find out why what you're doing is so bad. I refer you back to Re: Insert timestamp using datareader to oracle date - Visual Basic Discussion Boards[^]

                      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                      Dave Kreskowiak

                      K Offline
                      K Offline
                      kerek2
                      wrote on last edited by
                      #10

                      Hi Sir, I'm try to use Parameter but got this error :

                      Failed to convert parameter value from a String to a DateTime.

                      My coding like this :

                       oracmd.CommandText = " INSERT INTO ASIS.TIMECLOCK\_DATE(TD\_CARDHOLDER\_ID,TD\_EVENT\_DATE,TD\_FIRST\_IN,TD\_IN\_READER,TD\_IP\_CONTROLLER,TD\_TYPE) " & \_
                                                      " VALUES (@CARDHOLDERID,(@EVENTDATE),(@FIRSTIN),@READER,@IP,@TYPE)"
                      
                      
                      
                                  oracmd.Parameters.Add("@CARDHOLDERID", OracleType.VarChar).Value = "" & IBSSDR.Item("ID") & ""
                                  oracmd.Parameters.Add("@EVENTDATE", OracleType.DateTime).Value = "TO\_DATE('06/10/2020 09:30:00','dd/mm/yyyy hh:mi:ss am')"
                                  oracmd.Parameters.Add("@FIRSTIN", OracleType.DateTime).Value = "TO\_DATE('06/10/2020 09:30:00','dd/mm/yyyy hh:mi:ss am')"
                                  oracmd.Parameters.Add("@READER", OracleType.VarChar).Value = "" & IBSSDR.Item("DEVICE\_ID") & ""
                                  oracmd.Parameters.Add("@TYPE", OracleType.VarChar).Value = "CHECKIN"
                      
                            
                      
                                  oracmd.CommandType = CommandType.Text
                      

                      My oracle using format like this : dd/mm/yyyy hh:mi:ss am'

                      anyone got idea to hlep me?..Plzz

                      Richard DeemingR D 2 Replies Last reply
                      0
                      • K kerek2

                        Hi Sir, I'm try to use Parameter but got this error :

                        Failed to convert parameter value from a String to a DateTime.

                        My coding like this :

                         oracmd.CommandText = " INSERT INTO ASIS.TIMECLOCK\_DATE(TD\_CARDHOLDER\_ID,TD\_EVENT\_DATE,TD\_FIRST\_IN,TD\_IN\_READER,TD\_IP\_CONTROLLER,TD\_TYPE) " & \_
                                                        " VALUES (@CARDHOLDERID,(@EVENTDATE),(@FIRSTIN),@READER,@IP,@TYPE)"
                        
                        
                        
                                    oracmd.Parameters.Add("@CARDHOLDERID", OracleType.VarChar).Value = "" & IBSSDR.Item("ID") & ""
                                    oracmd.Parameters.Add("@EVENTDATE", OracleType.DateTime).Value = "TO\_DATE('06/10/2020 09:30:00','dd/mm/yyyy hh:mi:ss am')"
                                    oracmd.Parameters.Add("@FIRSTIN", OracleType.DateTime).Value = "TO\_DATE('06/10/2020 09:30:00','dd/mm/yyyy hh:mi:ss am')"
                                    oracmd.Parameters.Add("@READER", OracleType.VarChar).Value = "" & IBSSDR.Item("DEVICE\_ID") & ""
                                    oracmd.Parameters.Add("@TYPE", OracleType.VarChar).Value = "CHECKIN"
                        
                              
                        
                                    oracmd.CommandType = CommandType.Text
                        

                        My oracle using format like this : dd/mm/yyyy hh:mi:ss am'

                        anyone got idea to hlep me?..Plzz

                        Richard DeemingR Offline
                        Richard DeemingR Offline
                        Richard Deeming
                        wrote on last edited by
                        #11

                        Why are you converting all of your parameter values to strings? Use the appropriate .NET type instead:

                        oracmd.CommandText = " INSERT INTO ASIS.TIMECLOCK_DATE(TD_CARDHOLDER_ID,TD_EVENT_DATE,TD_FIRST_IN,TD_IN_READER,TD_IP_CONTROLLER,TD_TYPE) " & _
                        " VALUES (@CARDHOLDERID, @EVENTDATE, @FIRSTIN, @READER, @IP, @TYPE)"

                        oracmd.Parameters.Add("@CARDHOLDERID", OracleType.VarChar).Value = IBSSDR.Item("ID")
                        oracmd.Parameters.Add("@EVENTDATE", OracleType.DateTime).Value = New DateTime(2020, 10, 6, 9, 30, 0)
                        oracmd.Parameters.Add("@FIRSTIN", OracleType.DateTime).Value = New DateTime(2020, 10, 6, 9, 30, 0)
                        oracmd.Parameters.Add("@READER", OracleType.VarChar).Value = IBSSDR.Item("DEVICE_ID")
                        oracmd.Parameters.Add("@TYPE", OracleType.VarChar).Value = "CHECKIN"


                        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                        K 1 Reply Last reply
                        0
                        • K kerek2

                          Hi Sir, I'm try to use Parameter but got this error :

                          Failed to convert parameter value from a String to a DateTime.

                          My coding like this :

                           oracmd.CommandText = " INSERT INTO ASIS.TIMECLOCK\_DATE(TD\_CARDHOLDER\_ID,TD\_EVENT\_DATE,TD\_FIRST\_IN,TD\_IN\_READER,TD\_IP\_CONTROLLER,TD\_TYPE) " & \_
                                                          " VALUES (@CARDHOLDERID,(@EVENTDATE),(@FIRSTIN),@READER,@IP,@TYPE)"
                          
                          
                          
                                      oracmd.Parameters.Add("@CARDHOLDERID", OracleType.VarChar).Value = "" & IBSSDR.Item("ID") & ""
                                      oracmd.Parameters.Add("@EVENTDATE", OracleType.DateTime).Value = "TO\_DATE('06/10/2020 09:30:00','dd/mm/yyyy hh:mi:ss am')"
                                      oracmd.Parameters.Add("@FIRSTIN", OracleType.DateTime).Value = "TO\_DATE('06/10/2020 09:30:00','dd/mm/yyyy hh:mi:ss am')"
                                      oracmd.Parameters.Add("@READER", OracleType.VarChar).Value = "" & IBSSDR.Item("DEVICE\_ID") & ""
                                      oracmd.Parameters.Add("@TYPE", OracleType.VarChar).Value = "CHECKIN"
                          
                                
                          
                                      oracmd.CommandType = CommandType.Text
                          

                          My oracle using format like this : dd/mm/yyyy hh:mi:ss am'

                          anyone got idea to hlep me?..Plzz

                          D Offline
                          D Offline
                          Dave Kreskowiak
                          wrote on last edited by
                          #12

                          DateTime values do not have a format while stored in the database. The format is only applied when the value is displayed, either by the query tool you're using to test the query or by your own application. There is no format when stored by the database and that's what's tripping you up.

                          Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                          Dave Kreskowiak

                          1 Reply Last reply
                          0
                          • Richard DeemingR Richard Deeming

                            Why are you converting all of your parameter values to strings? Use the appropriate .NET type instead:

                            oracmd.CommandText = " INSERT INTO ASIS.TIMECLOCK_DATE(TD_CARDHOLDER_ID,TD_EVENT_DATE,TD_FIRST_IN,TD_IN_READER,TD_IP_CONTROLLER,TD_TYPE) " & _
                            " VALUES (@CARDHOLDERID, @EVENTDATE, @FIRSTIN, @READER, @IP, @TYPE)"

                            oracmd.Parameters.Add("@CARDHOLDERID", OracleType.VarChar).Value = IBSSDR.Item("ID")
                            oracmd.Parameters.Add("@EVENTDATE", OracleType.DateTime).Value = New DateTime(2020, 10, 6, 9, 30, 0)
                            oracmd.Parameters.Add("@FIRSTIN", OracleType.DateTime).Value = New DateTime(2020, 10, 6, 9, 30, 0)
                            oracmd.Parameters.Add("@READER", OracleType.VarChar).Value = IBSSDR.Item("DEVICE_ID")
                            oracmd.Parameters.Add("@TYPE", OracleType.VarChar).Value = "CHECKIN"


                            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                            K Offline
                            K Offline
                            kerek2
                            wrote on last edited by
                            #13

                            Sir, The datetime value is taking form another database (Firebird) using Datareader(IBSDDR.item("")), so i don't need to convert to_date when insert into ORacle sir?...Plz guide me, thanks in advanced :)

                            1 Reply Last reply
                            0
                            • D Dave Kreskowiak

                              It may work now, but DO NOT get into the habit of using string concatenation to build SQL queries like you have. Google for "SQL Injection Attack" to find out why what you're doing is so bad. I refer you back to Re: Insert timestamp using datareader to oracle date - Visual Basic Discussion Boards[^]

                              Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                              Dave Kreskowiak

                              K Offline
                              K Offline
                              kerek2
                              wrote on last edited by
                              #14

                              Hi Sir When i'm using Parameter got this error :-

                              ORA-01008: not all variables bound

                              Can u advise me what wrong..

                              oracmd.CommandText = " INSERT INTO ASIS.TIMECLOCK_DATE(TD_CARDHOLDER_ID,TD_EVENT_DATE,TD_FIRST_IN,TD_IN_READER,TD_IP_CONTROLLER,TD_TYPE) " & _
                              " VALUES (:CARDHOLDERID,to_date(:EVENTDATE,'dd/mm/yyyy hh:mi:ss am'),to_date(:FIRSTIN,'dd/mm/yyyy hh:mi:ss am'),:READER,:IP,:TYPE)"

                              oracmd.Parameters.Add(":CARDHOLDERID", OracleType.VarChar).Value = "" & IBSSDR.Item("ID") & ""
                              oracmd.Parameters.Add(":EVENTDATE", OracleType.DateTime).Value = ("" & IBSSDR.Item("EVENT_DATE").ToString & "")
                              oracmd.Parameters.Add(":FIRSTIN", OracleType.DateTime).Value = ("" & IBSSDR.Item("EVENT_DATE").ToString & "")

                                          oracmd.Parameters.Add(":READER", OracleType.VarChar).Value = "" & IBSSDR.Item("DEVICE\_ID") & ""
                                          oracmd.Parameters.Add(":TYPE", OracleType.VarChar).Value = "CHECKIN"
                              
                                    
                              
                                          oracmd.CommandType = CommandType.Text
                              

                              ...thank you

                              D V 2 Replies Last reply
                              0
                              • K kerek2

                                Hi Sir When i'm using Parameter got this error :-

                                ORA-01008: not all variables bound

                                Can u advise me what wrong..

                                oracmd.CommandText = " INSERT INTO ASIS.TIMECLOCK_DATE(TD_CARDHOLDER_ID,TD_EVENT_DATE,TD_FIRST_IN,TD_IN_READER,TD_IP_CONTROLLER,TD_TYPE) " & _
                                " VALUES (:CARDHOLDERID,to_date(:EVENTDATE,'dd/mm/yyyy hh:mi:ss am'),to_date(:FIRSTIN,'dd/mm/yyyy hh:mi:ss am'),:READER,:IP,:TYPE)"

                                oracmd.Parameters.Add(":CARDHOLDERID", OracleType.VarChar).Value = "" & IBSSDR.Item("ID") & ""
                                oracmd.Parameters.Add(":EVENTDATE", OracleType.DateTime).Value = ("" & IBSSDR.Item("EVENT_DATE").ToString & "")
                                oracmd.Parameters.Add(":FIRSTIN", OracleType.DateTime).Value = ("" & IBSSDR.Item("EVENT_DATE").ToString & "")

                                            oracmd.Parameters.Add(":READER", OracleType.VarChar).Value = "" & IBSSDR.Item("DEVICE\_ID") & ""
                                            oracmd.Parameters.Add(":TYPE", OracleType.VarChar).Value = "CHECKIN"
                                
                                      
                                
                                            oracmd.CommandType = CommandType.Text
                                

                                ...thank you

                                D Offline
                                D Offline
                                Dave Kreskowiak
                                wrote on last edited by
                                #15

                                You're trying to convert date strings being passed to the parameters to date values in the SQL VALUES clause. Don't do that because all you have to do is pass in DateTime values WITHOUT using "to_date" in the SQL. And what's with the "" & garbage? Get rid of stuff. It's useless, unless you want to make the code harder to read and debug.

                                oracmd.CommandText = " INSERT INTO ASIS.TIMECLOCK_DATE(TD_CARDHOLDER_ID,TD_EVENT_DATE,TD_FIRST_IN,TD_IN_READER,TD_IP_CONTROLLER,TD_TYPE) " & _
                                " VALUES (:CARDHOLDERID, :EVENTDATE, :FIRSTIN, :READER, :IP, :TYPE)"

                                oracmd.Parameters.Add(":CARDHOLDERID", OracleType.VarChar).Value = IBSSDR.Item("ID") oracmd.Parameters.Add(":EVENTDATE", OracleType.DateTime).Value = IBSSDR.Item("EVENT_DATE")
                                oracmd.Parameters.Add(":FIRSTIN", OracleType.DateTime).Value = IBSSDR.Item("EVENT_DATE")
                                oracmd.Parameters.Add(":READER", OracleType.VarChar).Value = IBSSDR.Item("DEVICE_ID")
                                oracmd.Parameters.Add(":TYPE", OracleType.VarChar).Value = "CHECKIN"

                                Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                                Dave Kreskowiak

                                K 1 Reply Last reply
                                0
                                • K kerek2

                                  Hi Sir When i'm using Parameter got this error :-

                                  ORA-01008: not all variables bound

                                  Can u advise me what wrong..

                                  oracmd.CommandText = " INSERT INTO ASIS.TIMECLOCK_DATE(TD_CARDHOLDER_ID,TD_EVENT_DATE,TD_FIRST_IN,TD_IN_READER,TD_IP_CONTROLLER,TD_TYPE) " & _
                                  " VALUES (:CARDHOLDERID,to_date(:EVENTDATE,'dd/mm/yyyy hh:mi:ss am'),to_date(:FIRSTIN,'dd/mm/yyyy hh:mi:ss am'),:READER,:IP,:TYPE)"

                                  oracmd.Parameters.Add(":CARDHOLDERID", OracleType.VarChar).Value = "" & IBSSDR.Item("ID") & ""
                                  oracmd.Parameters.Add(":EVENTDATE", OracleType.DateTime).Value = ("" & IBSSDR.Item("EVENT_DATE").ToString & "")
                                  oracmd.Parameters.Add(":FIRSTIN", OracleType.DateTime).Value = ("" & IBSSDR.Item("EVENT_DATE").ToString & "")

                                              oracmd.Parameters.Add(":READER", OracleType.VarChar).Value = "" & IBSSDR.Item("DEVICE\_ID") & ""
                                              oracmd.Parameters.Add(":TYPE", OracleType.VarChar).Value = "CHECKIN"
                                  
                                        
                                  
                                              oracmd.CommandType = CommandType.Text
                                  

                                  ...thank you

                                  V Offline
                                  V Offline
                                  Victor Nijegorodov
                                  wrote on last edited by
                                  #16

                                  Where is the

                                  oracmd.Parameters.Add(":IP", ...)

                                  :confused:

                                  1 Reply Last reply
                                  0
                                  • D Dave Kreskowiak

                                    You're trying to convert date strings being passed to the parameters to date values in the SQL VALUES clause. Don't do that because all you have to do is pass in DateTime values WITHOUT using "to_date" in the SQL. And what's with the "" & garbage? Get rid of stuff. It's useless, unless you want to make the code harder to read and debug.

                                    oracmd.CommandText = " INSERT INTO ASIS.TIMECLOCK_DATE(TD_CARDHOLDER_ID,TD_EVENT_DATE,TD_FIRST_IN,TD_IN_READER,TD_IP_CONTROLLER,TD_TYPE) " & _
                                    " VALUES (:CARDHOLDERID, :EVENTDATE, :FIRSTIN, :READER, :IP, :TYPE)"

                                    oracmd.Parameters.Add(":CARDHOLDERID", OracleType.VarChar).Value = IBSSDR.Item("ID") oracmd.Parameters.Add(":EVENTDATE", OracleType.DateTime).Value = IBSSDR.Item("EVENT_DATE")
                                    oracmd.Parameters.Add(":FIRSTIN", OracleType.DateTime).Value = IBSSDR.Item("EVENT_DATE")
                                    oracmd.Parameters.Add(":READER", OracleType.VarChar).Value = IBSSDR.Item("DEVICE_ID")
                                    oracmd.Parameters.Add(":TYPE", OracleType.VarChar).Value = "CHECKIN"

                                    Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                                    Dave Kreskowiak

                                    K Offline
                                    K Offline
                                    kerek2
                                    wrote on last edited by
                                    #17

                                    Sir,

                                    The datetime value is taking form another database (Firebird) using Datareader(IBSDDR.item("")), so i don't need to convert to_date when insert into ORacle sir?...Plz guide me, thanks in advanced Smile | :)

                                    D 1 Reply Last reply
                                    0
                                    • K kerek2

                                      Sir,

                                      The datetime value is taking form another database (Firebird) using Datareader(IBSDDR.item("")), so i don't need to convert to_date when insert into ORacle sir?...Plz guide me, thanks in advanced Smile | :)

                                      D Offline
                                      D Offline
                                      Dave Kreskowiak
                                      wrote on last edited by
                                      #18

                                      OK, one last time. THERE IS NO SUCH THING AS A FORMAT FOR A DATETIME VALUE IN A DATABASE. ALWAYS use parameters to pass values into a query string. NEVER use string concatenation to build SQL queries.

                                      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                                      Dave Kreskowiak

                                      1 Reply Last reply
                                      0
                                      Reply
                                      • Reply as topic
                                      Log in to reply
                                      • Oldest to Newest
                                      • Newest to Oldest
                                      • Most Votes


                                      • Login

                                      • Don't have an account? Register

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • World
                                      • Users
                                      • Groups