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. Access Insert issue

Access Insert issue

Scheduled Pinned Locked Moved C#
databasehelptutorial
8 Posts 3 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
    kruegersck
    wrote on last edited by
    #1

    I am trying to insert a record into an Access 2007 DB. I am having an issue with a Memo field. I have tried double quotes, single quotes. I am at a loss on how to load this sentence: This is a Test If anybody has any ideas or sample code I would really appreciate.

    L G 2 Replies Last reply
    0
    • K kruegersck

      I am trying to insert a record into an Access 2007 DB. I am having an issue with a Memo field. I have tried double quotes, single quotes. I am at a loss on how to load this sentence: This is a Test If anybody has any ideas or sample code I would really appreciate.

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Have you looked at the Samples that come with Access? Have you looked for information on the Access Developer site[^]?

      led mike

      K 1 Reply Last reply
      0
      • L led mike

        Have you looked at the Samples that come with Access? Have you looked for information on the Access Developer site[^]?

        led mike

        K Offline
        K Offline
        kruegersck
        wrote on last edited by
        #3

        Do they examples of doing this using C#?

        L 1 Reply Last reply
        0
        • K kruegersck

          I am trying to insert a record into an Access 2007 DB. I am having an issue with a Memo field. I have tried double quotes, single quotes. I am at a loss on how to load this sentence: This is a Test If anybody has any ideas or sample code I would really appreciate.

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          An insert query for that is rather simple. Example: insert into someTable (aMemoField) values ('This is a test...') When you do it from code you should use a parameterised query, though. Then you don't have to worry about apostrophes and correctly escaping strings (which is rather crucial to protect against SQL injection attacks).

          Despite everything, the person most likely to be fooling you next is yourself.

          K 1 Reply Last reply
          0
          • G Guffa

            An insert query for that is rather simple. Example: insert into someTable (aMemoField) values ('This is a test...') When you do it from code you should use a parameterised query, though. Then you don't have to worry about apostrophes and correctly escaping strings (which is rather crucial to protect against SQL injection attacks).

            Despite everything, the person most likely to be fooling you next is yourself.

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

            Here is my updated Code utlizing a parameterised query. I still get an error on my Insert Command stating: Syntax error in INSERT INTO statement. The first field is a key and is a long int The second field is a Text Field 255 long Here is the code that does the insert. Please let me know of any issues. I can't find any: string commandText = "INSERT INTO Contact_Notes (Contact_ID,Note) VALUES(@Contact_ID,@Note)"; string strConcat = "**** " + g_ProfName + " " + DateTime.Now.ToString() + " **** " + txtNewNote.Text; conProspect.Open(); OleDbCommand cmd = new OleDbCommand(commandText,conProspect); cmd.Parameters.Add("@Contact_ID", lngContactId); cmd.Parameters.Add("@Note", strConcat); cmd.ExecuteNonQuery(); conProspect.Close(); cmd.Dispose(); As always thanks for all the help

            K G 2 Replies Last reply
            0
            • K kruegersck

              Here is my updated Code utlizing a parameterised query. I still get an error on my Insert Command stating: Syntax error in INSERT INTO statement. The first field is a key and is a long int The second field is a Text Field 255 long Here is the code that does the insert. Please let me know of any issues. I can't find any: string commandText = "INSERT INTO Contact_Notes (Contact_ID,Note) VALUES(@Contact_ID,@Note)"; string strConcat = "**** " + g_ProfName + " " + DateTime.Now.ToString() + " **** " + txtNewNote.Text; conProspect.Open(); OleDbCommand cmd = new OleDbCommand(commandText,conProspect); cmd.Parameters.Add("@Contact_ID", lngContactId); cmd.Parameters.Add("@Note", strConcat); cmd.ExecuteNonQuery(); conProspect.Close(); cmd.Dispose(); As always thanks for all the help

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

              If I remove the Note field. It works just fine...

              1 Reply Last reply
              0
              • K kruegersck

                Do they examples of doing this using C#?

                L Offline
                L Offline
                led mike
                wrote on last edited by
                #7

                kruegersck wrote:

                Do they examples of doing this using C#?

                kruegersck wrote:

                I still get an error on my Insert Command stating: Syntax error in INSERT INTO statement.

                If you have any intention of becoming a capable software developer I suggest you stop typing questions into forums and start researching and reading your own information. It is as valuable a skill and activity of a developer as any other, period.

                led mike

                1 Reply Last reply
                0
                • K kruegersck

                  Here is my updated Code utlizing a parameterised query. I still get an error on my Insert Command stating: Syntax error in INSERT INTO statement. The first field is a key and is a long int The second field is a Text Field 255 long Here is the code that does the insert. Please let me know of any issues. I can't find any: string commandText = "INSERT INTO Contact_Notes (Contact_ID,Note) VALUES(@Contact_ID,@Note)"; string strConcat = "**** " + g_ProfName + " " + DateTime.Now.ToString() + " **** " + txtNewNote.Text; conProspect.Open(); OleDbCommand cmd = new OleDbCommand(commandText,conProspect); cmd.Parameters.Add("@Contact_ID", lngContactId); cmd.Parameters.Add("@Note", strConcat); cmd.ExecuteNonQuery(); conProspect.Close(); cmd.Dispose(); As always thanks for all the help

                  G Offline
                  G Offline
                  Guffa
                  wrote on last edited by
                  #8

                  Note is a reserved keyword in the JET database driver. Change the name of the field, or if that is not practically possible, put brackets around the name in the query: [Note].

                  Despite everything, the person most likely to be fooling you next is yourself.

                  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