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
| protected void btSupprimer_Click(object sender, EventArgs e)
{
string message = "Problème lors de la connexion";
string requete1, requete2;
SqlConnection connexion = new SqlConnection("Data Source=STQY-589\\SQLEXPRESS; Initial Catalog=DossierIndividuel;Integrated Security=True");
List<string[]> list = new List<string[]>();
int nbLigne = gvSalarie.Rows.Count;
for (int i = 0; i < nbLigne; i++)
{
list.Add(new string[2]{gvSalarie.DataKeys[i]["matricule"].ToString(),
gvSalarie.DataKeys[i]["typeDocument"].ToString()});
if (((CheckBox)gvSalarie.Rows[i].FindControl("uneSelection")).Checked)
{
try
{
if (connexion.State == ConnectionState.Closed)
{
connexion.Open();
}
requete1 = "DELETE FROM [DOCUMENT] " +
"WHERE [matricule] = '" + gvSalarie.DataKeys[i]["matricule"].ToString() + "' " +
"AND [typeDocument] = '" + gvSalarie.DataKeys[i]["typeDocument"].ToString() + "' ";
requete2 = "DELETE FROM [TABLEAU] " +
"WHERE [matricule] = '" + gvSalarie.DataKeys[i]["matricule"].ToString() + "' " +
"AND [typeDocument] = '" + gvSalarie.DataKeys[i]["typeDocument"].ToString() + "' ";
// Exécution de la requête et affichage du GridView
SqlCommand commande1 = new SqlCommand(requete1, connexion);
SqlDataAdapter sqlDA1 = new SqlDataAdapter(commande1);
DataSet ds1 = new DataSet();
sqlDA1.Fill(ds1);
SqlCommand commande2 = new SqlCommand(requete2, connexion);
SqlDataAdapter sqlDA2 = new SqlDataAdapter(commande2);
DataSet ds2 = new DataSet();
sqlDA2.Fill(ds2);
gvSalarie.DataSource = ds2;
gvSalarie.DataBind();
EnableViewState = true;
commande1.Dispose();
commande2.Dispose();
// Suppression du fichier
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
connexion.Close();
}
}
if (list.Count > 0)
{
Session["ListeDocSalarie"] = list;
}
recherche();
} |