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 lobjet 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!");
} |
Partager