How to prevent duplicate registration/name change/social reason

Asked

Viewed 1,253 times

0

In a register, c# windows form, where I use CPF s or CNPJ s, which is the best way to prevent duplicate names/social reason in inclusion or change.

For example it may happen that in the change the user enters a name/reason that is already registered.

Using names to search would not be indicated because the spaces between can be interpreted as differentiators ex: "William da Silva" and "William da Silva".

What is the best approach to this problem?

  • 1

    GIVE details of what you are doing. Is this a database, a list? Put a code.

  • 1

    The best way to prevent duplicity is to check if there is already another registered... As for names, two or more people may have the same name, and be different people, regardless of the number of spaces. Now, a well-made system would no longer hold double spaces where there are no double spaces, let’s face it. As for your question, you need more details, as this is very broad and open to imagination. Reading suggestion: [Ask] and [Help].

  • Learn REGEX, regular expressions, only in this way is it possible to do it. And this has to be done by consulting the database doing the analysis and before changing in the database insert a REGEX for validation

  • I thank everyone because the answers already gave me a north, despite the theme is vague. After create a post with more specific questions.

2 answers

1

The way I use to check is through the following query

select Id from Tabela where Id <> @Id and Cpf = @Cpf

Thus, if the query returns any result, it means that the record already exists in the database.

The parameter @Id is your primary key soon when it is a new record, its value will be 0 comparing only the second parameter, and this is what you want not to be duplicated, which in my example is the @Cpf.

1

Look what I would do in this case is put in the field of your table it as Constraint, so the bank didn’t let you enter a record with the same value. It would give you an error. You can catch this error in Try catch and inform the user.

Browse to read about Constraint in table fields.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.