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. C#
  4. Problem whit inserting date - Oracle and C#

Problem whit inserting date - Oracle and C#

Scheduled Pinned Locked Moved C#
helpcsharpdatabaseoraclequestion
7 Posts 7 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.
  • E Offline
    E Offline
    E_Gold
    wrote on last edited by
    #1

    Hi I have Date Var in Oracle, and I try to insert Data from my C# program sql = "insert into Table(MyDate) values (" + convert.todatetime(txt) + ")"; I get an Error, what can i do ?

    G P D F 4 Replies Last reply
    0
    • E E_Gold

      Hi I have Date Var in Oracle, and I try to insert Data from my C# program sql = "insert into Table(MyDate) values (" + convert.todatetime(txt) + ")"; I get an Error, what can i do ?

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      E_Gold wrote:

      I get an Error, what can i do ?

      If I were you, I'd post the error here.

      E_Gold wrote:

      sql = "insert into Table(MyDate) values (" + convert.todatetime(txt) + ")";

      Use parameters instead of concatenation[^]

      Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

      1 Reply Last reply
      0
      • E E_Gold

        Hi I have Date Var in Oracle, and I try to insert Data from my C# program sql = "insert into Table(MyDate) values (" + convert.todatetime(txt) + ")"; I get an Error, what can i do ?

        P Offline
        P Offline
        prubyholl
        wrote on last edited by
        #3

        it will be nice if u paste ur error msg here though i find a prob with your code. I just want to be sure

        D 1 Reply Last reply
        0
        • E E_Gold

          Hi I have Date Var in Oracle, and I try to insert Data from my C# program sql = "insert into Table(MyDate) values (" + convert.todatetime(txt) + ")"; I get an Error, what can i do ?

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          What is the error? I somehow feel it is related to conversion. Check if txt is a valid date.

          जय हिंद

          1 Reply Last reply
          0
          • E E_Gold

            Hi I have Date Var in Oracle, and I try to insert Data from my C# program sql = "insert into Table(MyDate) values (" + convert.todatetime(txt) + ")"; I get an Error, what can i do ?

            F Offline
            F Offline
            Fayu
            wrote on last edited by
            #5
            1. Oracle expects date to be in a certain format. If your table name is MyTable with column MyDate, use bind variables to pass values. Do this: sql = "Insert Into Mytable(MyDate) Values(:Date)"; OracleConnection conn = ... OracleCommand cmd = conn.CreateCommand(); cmd.Parameter.AddWithValue("Date", Convert.ToDateTime(txt)); ...

            modified on Monday, March 30, 2009 2:44 PM

            T 1 Reply Last reply
            0
            • P prubyholl

              it will be nice if u paste ur error msg here though i find a prob with your code. I just want to be sure

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

              It would be even nicer if you didn't use SMSSpeak to write your posts.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008

              1 Reply Last reply
              0
              • F Fayu
                1. Oracle expects date to be in a certain format. If your table name is MyTable with column MyDate, use bind variables to pass values. Do this: sql = "Insert Into Mytable(MyDate) Values(:Date)"; OracleConnection conn = ... OracleCommand cmd = conn.CreateCommand(); cmd.Parameter.AddWithValue("Date", Convert.ToDateTime(txt)); ...

                modified on Monday, March 30, 2009 2:44 PM

                T Offline
                T Offline
                Thomas Krojer
                wrote on last edited by
                #7

                You can also use the 'TO_DATE(..)' function from Oracle SQL.

                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