Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Gridview update numeric values

Gridview update numeric values

Scheduled Pinned Locked Moved ASP.NET
helpannouncement
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amina89
    wrote on last edited by
    #1

    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

    H 1 Reply Last reply
    0
    • A amina89

      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

      H Offline
      H Offline
      Hiren solanki
      wrote on last edited by
      #2

      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

      A 1 Reply Last reply
      0
      • H Hiren solanki

        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

        A Offline
        A Offline
        amina89
        wrote on last edited by
        #3

        Hi, I have any error message(unless the marks(note) field is empty) but the code does not update data ; Thanks .

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups