Bonjour, si je mets "Re -" c'est pour faire suite à ce poste.
J'ai bien essayé de mettre en application l'autre post, mais rien à faire, il ne veux pas fonctionner. Pour les méthodes Update et Delete, j'ai des exceptions "DBConcurrency" et pour la méthode Insert, il m'insert un champ null
le remplissage du dataGridView s'effectue selon ce code :
Voici la partie situé dans un bouton, afin d'effectuer la mise à jour :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 _MySQLConnection.ConnectionString = this._ConnectionString; _MySQLDataAdapter.SelectCommand = new MySqlCommand("SELECT * FROM test", _MySQLConnection); _MySQLDataAdapter.Fill(dataSet1, "test"); this.bindingSource1.DataSource = this.dataSet1; this.bindingSource1.DataMember = "test"; this.dataGridView1.DataSource = this.bindingSource1;
J'ai essayé de suivre l'exemple donné par Neguib au mieux, mais je pense avoir oublier un truc.
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 // paramétrage commande DELETE _MySQLDataAdapter.DeleteCommand = new MySql.Data.MySqlClient.MySqlCommand("DELETE FROM test WHERE test.id = @id", _MySQLConnection); MySql.Data.MySqlClient.MySqlParameter _MySQLDeleteParameter = _MySQLDataAdapter.DeleteCommand.Parameters.Add("@id", MySql.Data.MySqlClient.MySqlDbType.UInt32); _MySQLDeleteParameter.SourceColumn = "id"; _MySQLDeleteParameter.SourceVersion = DataRowVersion.Original; // paramétrage commande INSERT _MySQLDataAdapter.InsertCommand = new MySqlCommand("INSERT INTO test (nom) VALUES (@nom)", _MySQLConnection); _MySQLDataAdapter.InsertCommand.Parameters.Add("@nom", MySql.Data.MySqlClient.MySqlDbType.VarString, 45, "nom"); MySqlParameter _MySQLInsertParameter = _MySQLDataAdapter.InsertCommand.Parameters.Add("@id", MySql.Data.MySqlClient.MySqlDbType.UInt32); _MySQLInsertParameter.SourceColumn = "id"; _MySQLInsertParameter.SourceVersion = DataRowVersion.Original; // 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"); MySqlParameter _MySQLUpdateParameter = _MySQLDataAdapter.UpdateCommand.Parameters.Add("@id", MySql.Data.MySqlClient.MySqlDbType.UInt32); _MySQLUpdateParameter.SourceColumn = "id"; _MySQLUpdateParameter.SourceVersion = DataRowVersion.Original; // mise-à-jour _MySQLDataAdapter.Update(this.dataSet1, "test");
Partager