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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL Insert Error

SQL Insert Error

Scheduled Pinned Locked Moved Database
databasetestingbeta-testinghelpquestion
9 Posts 4 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.
  • C Offline
    C Offline
    cynnerg
    wrote on last edited by
    #1

    I am using this SQL query to insert into an access database using oleDbCommand: INSERT INTO Events (ID, Code, Hour, Day, Location, Name, Cost) VALUES (0, 'code', '5:05 pm', '11/3/2004', 'loc', 'name', '23.56') I keep getting an insert error, although when testing the query through Access it works fine. I have tried both using command parameters and hard-coding the data in as it is above, with the same results. Any suggestions?

    C R R 3 Replies Last reply
    0
    • C cynnerg

      I am using this SQL query to insert into an access database using oleDbCommand: INSERT INTO Events (ID, Code, Hour, Day, Location, Name, Cost) VALUES (0, 'code', '5:05 pm', '11/3/2004', 'loc', 'name', '23.56') I keep getting an insert error, although when testing the query through Access it works fine. I have tried both using command parameters and hard-coding the data in as it is above, with the same results. Any suggestions?

      C Offline
      C Offline
      cynnerg
      wrote on last edited by
      #2

      Here is the entire source that I have so far in this section: ds = New DataSet myCommand.Fill(ds, "Data") id = ds.Tables("DATA").Rows.Count() txtID.Text = id strQuery = "INSERT INTO Events (ID, Code, Hour, Day, Location, Name, Cost) VALUES (" _ & Int(id) & ", '" _ & txtCode.Text & "', '" _ & txtTime.Text & "', '" _ & txtDate.Text & "', '" _ & txtLocation.Text & "', '" _ & txtName.Text & "', '" _ & txtCost.Text & "')" cmd = New OleDbCommand(strQuery, myConnection) cmd.ExecuteNonQuery()

      G 1 Reply Last reply
      0
      • C cynnerg

        Here is the entire source that I have so far in this section: ds = New DataSet myCommand.Fill(ds, "Data") id = ds.Tables("DATA").Rows.Count() txtID.Text = id strQuery = "INSERT INTO Events (ID, Code, Hour, Day, Location, Name, Cost) VALUES (" _ & Int(id) & ", '" _ & txtCode.Text & "', '" _ & txtTime.Text & "', '" _ & txtDate.Text & "', '" _ & txtLocation.Text & "', '" _ & txtName.Text & "', '" _ & txtCost.Text & "')" cmd = New OleDbCommand(strQuery, myConnection) cmd.ExecuteNonQuery()

        G Offline
        G Offline
        Guillermo Rivero
        wrote on last edited by
        #3

        The ID column, is Autonumeric ? The Hour and Day Column, what type are they ? Free your mind...

        C 1 Reply Last reply
        0
        • G Guillermo Rivero

          The ID column, is Autonumeric ? The Hour and Day Column, what type are they ? Free your mind...

          C Offline
          C Offline
          cynnerg
          wrote on last edited by
          #4

          ID is standard number. Handling the increment in code. All other columns are text.

          G 2 Replies Last reply
          0
          • C cynnerg

            ID is standard number. Handling the increment in code. All other columns are text.

            G Offline
            G Offline
            Guillermo Rivero
            wrote on last edited by
            #5

            I don't see nothing wrong with your select statement. Did you check the size of the fields ? What's the error description ? Free your mind...

            1 Reply Last reply
            0
            • C cynnerg

              ID is standard number. Handling the increment in code. All other columns are text.

              G Offline
              G Offline
              Guillermo Rivero
              wrote on last edited by
              #6

              Are you repeating a value on a column that is indexed as primary key ? Free your mind...

              C 1 Reply Last reply
              0
              • G Guillermo Rivero

                Are you repeating a value on a column that is indexed as primary key ? Free your mind...

                C Offline
                C Offline
                cynnerg
                wrote on last edited by
                #7

                Uhhhm, no. And no. In fact, right now that table is empty. And everything is configured as a text value. I was really hoping it was the SQL, but now it looks like maybe the code itself. Or something else. Funny thing. That exact same code (with different fields and parameters) works perfectly in the same database, different table. I'll have to look at it more thoroughly, I guess. Thanks

                1 Reply Last reply
                0
                • C cynnerg

                  I am using this SQL query to insert into an access database using oleDbCommand: INSERT INTO Events (ID, Code, Hour, Day, Location, Name, Cost) VALUES (0, 'code', '5:05 pm', '11/3/2004', 'loc', 'name', '23.56') I keep getting an insert error, although when testing the query through Access it works fine. I have tried both using command parameters and hard-coding the data in as it is above, with the same results. Any suggestions?

                  R Offline
                  R Offline
                  Roger Wright
                  wrote on last edited by
                  #8

                  One possibility is that Access requires literal date data to be set off by #, as in #11/03/2004#. This may apply to time values, as well, though Clippy won't tell me that no matter how hard I ask. "Another day done - All targets met; all systems fully operational; all customers satisfied; all staff keen and well motivated; all pigs fed and ready to fly" - Jennie A.

                  1 Reply Last reply
                  0
                  • C cynnerg

                    I am using this SQL query to insert into an access database using oleDbCommand: INSERT INTO Events (ID, Code, Hour, Day, Location, Name, Cost) VALUES (0, 'code', '5:05 pm', '11/3/2004', 'loc', 'name', '23.56') I keep getting an insert error, although when testing the query through Access it works fine. I have tried both using command parameters and hard-coding the data in as it is above, with the same results. Any suggestions?

                    R Offline
                    R Offline
                    rahtrow
                    wrote on last edited by
                    #9

                    Do you have a specific error message? What is the schema definition of the Events table? (what are the field types and sizes for each field in the table) Any identity/autogenerated columns? Is there primary key defined?

                    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