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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
private void button1_Click(object sender, EventArgs e)
{
string MaRequete;
ConnectionStringSettings parametreConnexion = ConfigurationManager.ConnectionStrings["sgbd"];
string MaChaineDeConnexion = parametreConnexion.ConnectionString;
SqlConnection MaConnection = new SqlConnection(MaChaineDeConnexion);
MaConnection.Open();
// Creation d'un objet Command
MaRequete = "SELECT * FROM Fiche";
SqlCommand MaCommandeSQL = new SqlCommand(MaRequete, MaConnection);
DataSet datasetSQL = new DataSet();
SqlDataAdapter dataAdapterSQL = new SqlDataAdapter(MaCommandeSQL);
try
{
dataAdapterSQL.Fill(datasetSQL, "Fiche");
MaRequete = "DELETE FROM Fiche WHERE No = '" + No + "' AND Prenom = '" + Prenom + "' AND Nom = '" + Nom + "'";
MaCommandeSQL = new SqlCommand(MaRequete, MaConnection);
MaCommandeSQL.Connection = MaConnection;
MaCommandeSQL.ExecuteScalar();
dataAdapterSQL.Update(datasetSQL, "Fiche");
datasetSQL.Tables["Fiche"].AcceptChanges();
SqlCommand command = new SqlCommand("SELECT * FROM Fiche", MaConnection);
dataAdapterSQL = new SqlDataAdapter(command);
dataAdapterSQL.SelectCommand.ExecuteNonQuery();
command = new SqlCommand("DELETE FROM Fiche WHERE No = '" + No + "' AND Prenom = '" + Prenom + "' AND Nom = '" + Nom + "'", MaConnection);
dataAdapterSQL = new SqlDataAdapter(command);
dataAdapterSQL.SelectCommand.ExecuteNonQuery();
dataAdapterSQL.DeleteCommand = command;
dataAdapterSQL.UpdateCommand = command;
dataAdapterSQL = new SqlDataAdapter(command);
dataAdapterSQL.Update(datasetSQL, "Fiche");
datasetSQL.Tables["Fiche"].AcceptChanges();
MaRequete = "SELECT * FROM Fiche";
MaCommandeSQL = new SqlCommand(MaRequete, MaConnection);
datasetSQL = new DataSet();
dataAdapterSQL = new SqlDataAdapter(MaCommandeSQL);
dataAdapterSQL.Fill(datasetSQL, "Fiche");
f.ficheDataGridView.DataSource = datasetSQL.Tables["Fiche"];
}
catch (SqlException se) { MessageBox.Show(se.Message); }
finally { MaConnection.Close(); }
this.Close();
f.Refresh();
} |