Bonjour,

J'aimerais que mon application sache a qu'elle moment il doit ecrire ou modifier mes champs dans ma table de donnée

j'ai essayé plusieur chose mais je n'y arrive pas.

j'ai trouvé ceci sur le net

INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6)
-> ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b)
http://dev.mysql.com/doc/refman/4.1/en/insert.html

En alternative il y a également la fonction replace décrite sur
http://dev.mysql.com/doc/refman/5.0/fr/replace.html
Je n'arrive pas a l'interpréter

je mets un morceau de mon code

Pouvez vous m'aider svp?

Merci a tous


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
using (wConnexion)
            {
                // Instancier l’objet Command
                using (MySqlCommand wCommand = wConnexion.CreateCommand())
                {
 
 
 
                        // UPDATE de la requette
                        wCommand.CommandText = "UPDATE `test` SET nom=@nom, prenom=@prenom, message=@message, sexe=@sexe";
                        wCommand.Parameters.AddWithValue("@nom", textBox2.Text);
                        wCommand.Parameters.AddWithValue("@prenom", textBox3.Text);
                        wCommand.Parameters.AddWithValue("@message", textBox4.Text);
                        wCommand.Parameters.AddWithValue("@sexe", comboBox2.Text);
 
 
                        // Insert de la requête
                        wCommand.CommandText = "INSERT INTO test (nom, prenom, message, sexe) VALUES (@nom, @prenom, @message, @sexe)";
                        wCommand.Parameters.AddWithValue("@nom", textBox2.Text);
                        wCommand.Parameters.AddWithValue("@prenom", textBox3.Text);
                        wCommand.Parameters.AddWithValue("@message", textBox4.Text);
                        wCommand.Parameters.AddWithValue("@sexe", comboBox2.Text);
 
 
                        // Exécution de la requête
                    try
                    {
                      wCommand.ExecuteNonQuery();
                        MessageBox.Show("Enregistrement effectué!");
                    }
                    catch (InvalidOperationException)
                    {
                        MessageBox.Show("Erreur impossible d'écrire dans la table!");
 
                    }