avoid duplicate records on a database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mercea
    New Member
    • Aug 2007
    • 35

    avoid duplicate records on a database

    hi all,

    How do i avoid duplicate records on my database? i have 4 textboxes that collect user information and this information is saved in the database. when a user fills the textboxes and clicks the submit button, i want to check through the database if the exact records exist in the database before the data is saved. if the user is registered on the database, he wont be allowed to login. how can i acheive this?

    i thought of using the comparevalidato r but i'm not sure how to proceed.

    thanks
  • phvfl
    Recognized Expert New Member
    • Aug 2007
    • 173

    #2
    Hi Mercea,

    You would struggle using a compare validator. The best way that I could think of would be to query the database using the submitted values from the user, if no records are returned then it is not already in the database.

    This could either be done through server code or through an AJAX request if you not want to wait for the page to postback

    Comment

    • zachwieja
      New Member
      • Sep 2007
      • 2

      #3
      Add a primary key to the table in the database. With the fields that cannot be duplicated. If you try to add a row with the same values then the query to insert the row will fail, then catch the exception to report the error back to the user.

      Comment

      • mercea
        New Member
        • Aug 2007
        • 35

        #4
        the problem with assigning a primary key is that the database contains a column for the login time which is recorded everytime the submit button is clicked so the values can never be the same. how do i do it server side? is it also possible to arrange the data in the gridview alphabetically?

        Comment

        • rohitbce
          New Member
          • Aug 2007
          • 30

          #5
          Hi
          In database you use the primary key
          In front end check if err no 2627 occur than catch that exception and send a err message you cant insert duplicate record
          thanks and Regard
          Rohit Jain

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by mercea
            hi all,

            How do i avoid duplicate records on my database? i have 4 textboxes that collect user information and this information is saved in the database. when a user fills the textboxes and clicks the submit button, i want to check through the database if the exact records exist in the database before the data is saved. if the user is registered on the database, he wont be allowed to login. how can i acheive this?

            i thought of using the comparevalidato r but i'm not sure how to proceed.

            thanks
            What do you mean by "user is registered"?
            Do you mean user with same username, or combination of username and password or any other exotic combination depending on what is being entered on your textboxes?
            I'd suggest a before insert trigger on the database itself for this and catch the resulting exception. I normally make the database do as much work for me as I'm doing on the front-end.

            Comment

            Working...