Gridview update numeric values
-
hello, I want insert student markes by aonce click using a gridview and this code:
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); myCommand.ExecuteNonQuery(); } } myConnection.Close(); }
but the code not work I tried the float and decimal and money for the type of note I tried float.parse, Decimal.Parse, convert.todecimal the code multiplies the values of the first row by 2 for each click on update button bizarre . help me please,thanks Écouter Lire phonétiquement
-
hello, I want insert student markes by aonce click using a gridview and this code:
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); myCommand.ExecuteNonQuery(); } } myConnection.Close(); }
but the code not work I tried the float and decimal and money for the type of note I tried float.parse, Decimal.Parse, convert.todecimal the code multiplies the values of the first row by 2 for each click on update button bizarre . help me please,thanks Écouter Lire phonétiquement
Could you please tell which exact error you are getting, Because I have a doubt on your SQL query CASE statement.
Regards, Hiren. "We owe a lot to the Indians, who taught us how to count, without which no worthwhile scientific discovery could have been made." - Einstein Microsoft Dynamics CRM
-
Could you please tell which exact error you are getting, Because I have a doubt on your SQL query CASE statement.
Regards, Hiren. "We owe a lot to the Indians, who taught us how to count, without which no worthwhile scientific discovery could have been made." - Einstein Microsoft Dynamics CRM