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. General Programming
  3. Managed C++/CLI
  4. Query Regarding Duplication Prevention

Query Regarding Duplication Prevention

Scheduled Pinned Locked Moved Managed C++/CLI
6 Posts 2 Posters 1 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.
  • S Offline
    S Offline
    Subramaniam s V
    wrote on last edited by
    #1

    Hi All, I am writing code snippet that insert records into a table which has a primary key on 2 columns..say for example Column X and Column Y.. I want to prevent duplication of records from being inserted into the table using C++..is there any way i can acheive this..i dont want to use Maps for storing the already inserted combination and thereby comparing before insertion..is there any other way to acheive this.. Thanks In Advance

    L 1 Reply Last reply
    0
    • S Subramaniam s V

      Hi All, I am writing code snippet that insert records into a table which has a primary key on 2 columns..say for example Column X and Column Y.. I want to prevent duplication of records from being inserted into the table using C++..is there any way i can acheive this..i dont want to use Maps for storing the already inserted combination and thereby comparing before insertion..is there any other way to acheive this.. Thanks In Advance

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

      Subramaniam s.V. wrote:

      is there any other way to acheive this..

      You mean like using the database? Yes there is.

      led mike

      S 2 Replies Last reply
      0
      • L led mike

        Subramaniam s.V. wrote:

        is there any other way to acheive this..

        You mean like using the database? Yes there is.

        led mike

        S Offline
        S Offline
        Subramaniam s V
        wrote on last edited by
        #3

        Can you tell me how we go about doing it?

        L 1 Reply Last reply
        0
        • L led mike

          Subramaniam s.V. wrote:

          is there any other way to acheive this..

          You mean like using the database? Yes there is.

          led mike

          S Offline
          S Offline
          Subramaniam s V
          wrote on last edited by
          #4

          In the sense, is there any other way to handle this using C++ itself? without using any other datastructure to store the information about already inserted records, is there a way to handle duplication?

          1 Reply Last reply
          0
          • S Subramaniam s V

            Can you tell me how we go about doing it?

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

            The obvious brute force way is to query the database for the key, however most modern databases allow you to put a unique constraint on the key which will cause the insert to fail. If you are interested in using a database solution ( I recommend it), try asking a question in the SQL forum here on CodeProject.

            led mike

            S 1 Reply Last reply
            0
            • L led mike

              The obvious brute force way is to query the database for the key, however most modern databases allow you to put a unique constraint on the key which will cause the insert to fail. If you are interested in using a database solution ( I recommend it), try asking a question in the SQL forum here on CodeProject.

              led mike

              S Offline
              S Offline
              Subramaniam s V
              wrote on last edited by
              #6

              yeah thats right Led. Ultimate solution would be to handle it in the database level. I completely agree with you on this point. Infact, my database by default handles this duplication. The problem is, my requirement is that, i need to insert records into a table by traversing up a Tree hierarchy and in my requirement there is a bright chance that duplicate records can be inserted into the database. when i try to insert a duplicate record it throws an error and comes out. All that I want is, if there is duplcaition, I want to skip that insertion from happening and proceed with further insertion of other records hope you got the problem now..if not let me know i ll explain you the scenario in detail

              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