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
|
private void Form2_Load(object sender, EventArgs e)
{
_MySQLConnection.ConnectionString = this._ConnectionString;
_MySQLDataAdapter.SelectCommand = new MySqlCommand("SELECT * FROM test", _MySQLConnection);
_MySQLDataAdapter.Fill(dataSet1, "test");
this.dataGridView1.DataSource = this.dataSet1.Tables[0];
}
private void button1_Click(object sender, EventArgs e)
{
// paramétrage commande DELETE
_MySQLDataAdapter.DeleteCommand = new MySql.Data.MySqlClient.MySqlCommand("DELETE FROM test WHERE test.id = ?id", _MySQLConnection);
_MySQLDataAdapter.DeleteCommand.Parameters.Add("?id", MySql.Data.MySqlClient.MySqlDbType.String, 0, "id");
_MySQLDataAdapter.DeleteCommand.Parameters["?id"].SourceVersion = DataRowVersion.Original;
// paramétrage commande INSERT
_MySQLDataAdapter.InsertCommand = new MySqlCommand("INSERT INTO test (nom) VALUES (?nom)", _MySQLConnection);
_MySQLDataAdapter.InsertCommand.Parameters.Add("?nom", MySqlDbType.VarString, 45,"nom");
// paramétrage commande UPDATE
_MySQLDataAdapter.UpdateCommand = new MySqlCommand("UPDATE test SET test.nom = ?nom WHERE test.id = ?id", _MySQLConnection);
_MySQLDataAdapter.UpdateCommand.Parameters.Add("?nom", MySqlDbType.VarString, 45, "nom");
_MySQLDataAdapter.UpdateCommand.Parameters.Add("?id", MySqlDbType.String, 0, "id");
_MySQLConnection.Open();
// mise-à-jour
_MySQLDataAdapter.Update(this.dataSet1, "test");
_MySQLConnection.Close();
} |
Partager