//con.Open();
private void button1_Click(object sender, EventArgs e) { try { ad.InsertCommand=new OleDbCommand ("INSERT INTO Personne VALUES (@ID,@Nom)",con); ad.InsertCommand.Parameters.Add("@ID",OleDbType.VarChar).Value=textBox1.Text.ToString(); ad.InsertCommand.Parameters.Add("@Nom",OleDbType.VarChar).Value=textBox2.Text.ToString(); //con.Open(); ad.InsertCommand.ExecuteNonQuery(); con.Close(); MessageBox.Show("SAVEDDDDDDDD"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void button4_Click(object sender, EventArgs e) { try { ad.SelectCommand = new OleDbCommand("SELECT * FROM Personne", con); ds.Clear(); ad.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; //con.Open(); ad.SelectCommand.ExecuteNonQuery(); con.Close(); MessageBox.Show("showwwwwwwwwwwww"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void button2_Click(object sender, EventArgs e) { try { ad.UpdateCommand = new OleDbCommand("UPDATE Personne SET Nom='" + textBox2.Text + "' WHERE (ID='" + textBox1 + "')", con); ad.UpdateCommand.ExecuteNonQuery(); con.Close(); MessageBox.Show("Updated"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void button3_Click(object sender, EventArgs e) { try { ad.DeleteCommand = new OleDbCommand("DELETE FROM Personne WHERE(ID='" + textBox1.Text + "')", con); ad.DeleteCommand.ExecuteNonQuery(); con.Close(); MessageBox.Show("DELETED"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionprivate void button2_Click(object sender, EventArgs e) { try {//dans ton message d erreur c est toujours le problème de la connexion? //si non regarde ton : ad.UpdateCommand = new OleDbCommand("UPDATE Personne SET Nom='" + textBox2.Text + "' WHERE (ID='" + textBox1 + "')", con); //******************************************************************************************* ("UPDATE Personne SET Nom='" + textBox2.Text + "' WHERE (ID='" + textBox1.text + "')", con);// //il manque au moins le .tetx dans textbox1 // //******************************************************************************************* }