Bonjour,
Ya 15 que je travail sur ce code mais sans résultat ,j'ai toujours ce message qu'il que soit les valeurs tapé sur la gridview et même s'elle est nulle.
Le format de la chaîne d'entrée est incorrect.
pour la ligne:
note1 = float.Parse(((TextBox)row.FindControl("note1")).Text);
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
| private void Update()
{
string cmd = "UPDATE EXAMEN SET NOTE = (CASE WHEN CODE_MATIERE = '1' then @note1 WHEN CODE_MATIERE = '2' then @note2 END) WHERE NUM_INSCRIPTION = @num;";
float 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("note1")).Text);
note2 = float.Parse(((TextBox)row.FindControl("note2")).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);
myCommand.ExecuteNonQuery();
}
myConnection.Close();
}
} |
1 2 3 4 5 6 7 8 9 10 11 12 13
| <asp:TemplateField HeaderText="Français">
<ItemTemplate>
<asp:Label ID="lblLastName1" runat="server" Text='<%# Eval("1") %>' Visible='<%# !(bool) IsInEditMode %>'></asp:Label>
<asp:TextBox ID="note1" runat="server" Text='<%# Eval("1") %>' Visible='<%# IsInEditMode %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Anglais">
<ItemStyle CssClass="td02" />
<ItemTemplate>
<asp:Label ID="lblLastName" runat="server" Text='<%# Eval("2") %>' Visible='<%# !(bool) IsInEditMode %>'></asp:Label>
<asp:TextBox ID="note2" runat="server" Text='<%# Eval("2") %>' Visible='<%# IsInEditMode %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField> |
Merci
Partager