Bonjour,
J'ai une gridview en edit mode j'essaye de mettre à jour toutes ses lignes à la fois pour voici mon code
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
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
56
57
58
59
60
61
62
 
  private void Update()
    {
 
        string cmd = @"UPDATE EXAMEN set NOTE= CASE 
WHEN CODE_MATIERE = '1' and @note1 =99  then '0'  
when CODE_MATIERE = '1' and @note1 <>99  then @note1  
        WHEN CODE_MATIERE = '2' and @note2 ='99'  then '0'  
when CODE_MATIERE = '2' and @note2 <>99  then @note2 END, PRESENCE=
CASE WHEN CODE_MATIERE = '1' and @note1 =99 then 'TRUE' 
when CODE_MATIERE = '2' and @note2 ='99'  then 'TRUE'  else 'FALSE'
 
end
WHERE NUM_INSCRIPTION = @num;";
 
 
        float note1, note2;
        string num;
        SqlCommand myCommand;
        SqlParameter param1, param2, param3;
 
        using (SqlConnection myConnection = new SqlConnection(ConnectionString))
        {
            myConnection.Open();
 
            foreach (GridViewRow row in GridView1.Rows)
            {
                note1 = float.Parse(((TextBox)row.FindControl("tmoy1")).Text);
                note2 = float.Parse(((TextBox)row.FindControl("tmoy4")).Text);
                num = ((Label)row.FindControl("lblUserID1")).Text;
 
                myCommand = new SqlCommand(cmd, myConnection);
 
                param1 = new SqlParameter("num", SqlDbType.VarChar, 4);
                param1.Value = num;
                myCommand.Parameters.Add(param1);
 
                param2 = new SqlParameter("note1", SqlDbType.Float, 2);
                param2.Value = note1;
                myCommand.Parameters.Add(param2);
 
                param3 = new SqlParameter("note2", SqlDbType.Float, 2);
                param3.Value = note2;
                myCommand.Parameters.Add(param3);
 
                if (note1 != null && note1 <= 20 && note1 >= 0 && note2 != null && note2 <= 20 && note2 >= 0)
                {
 
 
 myCommand.ExecuteNonQuery();
 
 
                }
                else { Response.Write("les données doivent etre entre 0 et 20"); }
 
 
                myConnection.Close();
            }       
 
        }
 
    }
le code fonctionne parfois et bloque d'autres ,je sais pas pourquoi .
est ce à cause de float ? si non ya t'elle une autre façon pour faire ça ?
merci