when i insert in mysql data base, i would like to avoid the duplication. what should i add in the "if" expression. the insert function is :
private void Inscrire_Click(object sender, EventArgs e)
{ //bouton insert
cmd = new MySqlCommand("INSERT INTO users (Matricule,mot_de_passe,Nom,Prenom) VALUES(@Matricule,@mot_de_passe,@Nom,@Prenom)", con);
cmd.Parameters.AddWithValue("@Matricule", textBox1.Text);
cmd.Parameters.AddWithValue("@mot_de_passe", textBox2.Text);
cmd.Parameters.AddWithValue("@Nom", textBox3.Text);
cmd.Parameters.AddWithValue("@Prenom", textBox4.Text);
MySqlDataReader dr;
// avoiding duplication of "Matricule"
// what can i add here?
if (textBox1.Text.Equals(""))
{
MessageBox.Show("existe déja");
}
else
{
cmd.ExecuteNonQuery();
MessageBox.Show("inscription réussite !");
Form1 f = new Form1();
f.ShowDialog();
}
}
French to English
Matricule - Id #
motte de passe - password
Nom - surname
prénom - firstname
I am not absolutely sure what you mean by avoiding duplication but if you mean to avoid inserting the same data then you can consider wrapping your
INSERT
in a stored procedure where you can check for existence of those data likeYou can then call this procedure in your
C#
code passing all the parameter what you are passing currently.