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
|
public void SupprimerEleve()
{
try
{
using(SQLiteConnection connexion = new SQLiteConnection("Data Source = GSMA.db; Version = 3;"))
{
connexion.Open();
SQLiteCommand recherche = new SQLiteCommand("SELECT MatriculeEleve FROM Eleve", connexion);
SQLiteDataReader dr = recherche.ExecuteReader();
string matricule = "";
while (dr.Read())
{
if (dr[0].ToString().Equals(txtMatricule.Text))
{
matricule = dr[0].ToString();
break;
}
}
if ((matricule.Equals(txtMatricule.Text)) && (!txtMatricule.Text.Equals(string.Empty)))
{
SQLiteCommand commande = new SQLiteCommand("DELETE FROM Eleve WHERE MatriculeEleve = '" + txtMatricule.Text + "'", connexion);
commande.ExecuteNonQuery();
MessageBox.Show("Elève supprimé !", "Suppression Elève", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
if (txtMatricule.Text.Equals(string.Empty))
{
MessageBox.Show("Entrez un numéro matricule svp !", "Erreur Matricule", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
MessageBox.Show("Ce numéro matricule n'existe pas !", "Matricule inexistant", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
connexion.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(string.Empty + ex, "Erreur Suppression", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
} |
Partager