  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                ปัญหาตอนนี้ของผมก็คือ ต้องการเรียก CommandField UpdateText="Update" ตัวนี้ เมื่อกด UpdateText="Update" แล้ว 
 
ให้ส่งค่า label ที่รับมาจาก ตาราง [Product] เพื่อที่จะเอาข้อมูลเดิมก่อนการแก้ไข ไปเก็บไว้ที่ ตาราง [log_activity] และให้ข้อมูลที่มีการอัพเดท ก็อัพเดทใน ตาราง [Product] ตามปกติ 
 
ซึ่งผมไม่มั่นใจว่าการเรียก e.commandName == Update ของผมนั้นถูกต้องรึเปล่า เพื่อเมื่อกด ปุ่ม Update มันเกิดการ Error ขึ้น ผลก็คือ ไม่สามารถ อัพเดท ที่ตาราง [Product] ได้ และ ไม่มีข้อมูลเดิมส่งไปยัง ตาราง [log_activity] 
 
 
 
Code (ASP) 
<asp:CommandField UpdateText="Update" ItemStyle-HorizontalAlign="center" ItemStyle-Width="100px" ButtonType="Image"  ShowEditButton="true" CancelText="Cancel" DeleteText="Delete" EditText="Edit"  HeaderText="Action" EditImageUrl="../assets/images/edit-file.png" UpdateImageUrl="../assets/images/edit-file-success.png" CancelImageUrl="../assets/images/edit-file-cancel.png" />
  
Code (XML) 
 
 
 
 
Code (ASP) 
protected void myGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Update")
                {
                    SqlConnection conn = new SqlConnection("Server=192.168.0.4;PASSWORD=F@753951;database=ReportHR; User id=sa; ");
                    conn.Open();
                    TextBox log1 = (TextBox)myGridview.FindControl("lbProduct");
                    TextBox log2 = (TextBox)myGridview.FindControl("lbSeatsused");
                    TextBox log3 = (TextBox)myGridview.FindControl("lbSeatsavailable");
                    TextBox log4 = (TextBox)myGridview.FindControl("lbExpired");
                    TextBox log5 = (TextBox)myGridview.FindControl("lbOverdeployed");
                strSQL = "INSERT INTO log_activity (product,seatsused,seatsavailable,expired,overdeployed) " +
                " VALUES ('" + log1.Text + "','" + log2.Text + "','" + log3.Text + "' " +
                " ,'" + log4.Text + "','" + log5.Text + "')";
                SqlCommand comm = new SqlCommand(strSQL, conn);
                    
                    objCmd = new SqlCommand(strSQL, objConn);
                    objCmd.ExecuteNonQuery();
                    loadData();
                }
           
        }		
 
 
 
 
 
 
ภาพฟ้อง Error 
 
 
 
 
 
  Tag : .NET, Web (ASP.NET), C#               
                        | 
           
          
            
		
  ประวัติการแก้ไข 2018-01-17 10:58:28	
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2018-01-17 10:34:26 | 
                      By :
                          chetlove08 | 
                      View :
                          1418 | 
                      Reply :
                          1 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  |