  | 
                       | 
          
            
               
                 Code การลบข้อมูลใน Datagrideview หรือ Grideview โดยใส่รหัสที่ต้องการลบใน txteqmnum เพื่อตรวจสอบหารหัสที่ตรงกัน(C#) 
 private void tsDelete_Click(object sender, EventArgs e)
        {   
            if (txteqmnum.Text.Trim() == "")
            {
                MessageBox.Show("กรุณาป้อนรหัสผู้จำหน่ายก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txteqmnum.Focus();
                return;
            }
         
            if (MessageBox.Show("คุณต้องการลบข้อมูลผู้จำหน่าย ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                tr = Conn.BeginTransaction();
                try
                {
                    sb.Remove(0, sb.Length);
                    sb.Append("DELETE  FROM Equipment");
                    sb.Append(" WHERE (eqmnum=@eqmnum)");
                    string sqlDelete;
                    sqlDelete = sb.ToString();
                    com.CommandText = sqlDelete;
                    com.CommandType = CommandType.Text;
                    com.Connection = Conn;
                    com.Transaction = tr;
                    com.Parameters.Clear();
                    com.Parameters.Add("@eqmnum", SqlDbType.VarChar).Value = txteqmnum.Text.Trim();
                    int result;
                    result = com.ExecuteNonQuery();
                    if (result == 0)
                    {
                        tr.Rollback();
                        MessageBox.Show("ชื่อรหัสผู้จำหน่ายที่คุณป้อน ไม่ถูกต้อง !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txteqmnum.SelectAll();
                    }
                    else
                    {
                        tr.Commit();
                        MessageBox.Show("ลบรายการผู้จำหน่ายเรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ClearEqm();
                        ShowdgvEqmList();
                    }
                }
                catch (Exception ex)
                {
                    tr.Rollback();
                    MessageBox.Show("เกิดข้อผิดพลาด เนื่องจาก " + ex.Message, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            ClearEqm();
            txteqmnum.Focus();
        }
                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2010-07-21 13:58:32 | 
                        By :
                            worlord | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             |