vergel aranas

vergel aranas

  • NA
  • 70
  • 13.6k

multipledelete

Jul 10 2012 12:42 PM
Hi Sir, I'm here again hopping for your help. Sir, how can i delete multiple row in list view with mysql? I have already a code for deleting but it work only in one row and when i check  and select more than one row it doesn't. How can i do that sir. Here is my code for delete.

        private void btnPdel_Click(object sender, EventArgs e)
        {
          
           
            foreach(int t in petlist.CheckedIndices)
            {
                string s = petlist.Items[t].Text.ToString();



                if (petlist.SelectedItems.Count > 0 )
                {
                    ListViewItem lv = petlist.SelectedItems[0];

                    string cid = lv.SubItems[6].Text;

                    string petdel = "Delete from petreg where petId = '" + s + "' and clientId ='" + cid + "'";
                    MySqlConnection connect = new MySqlConnection(conn);
                    MySqlCommand cmd = new MySqlCommand(petdel, connect);

                    connect.Open();
                    int execute = 0;
                    execute = cmd.ExecuteNonQuery();
                    connect.Close();
                    if (execute.Equals(1))
                    {
                        petload();
                        MessageBox.Show("Data was succesfully deleted", "Mysql says...", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    }
                    else
                    {
                        MessageBox.Show("The data is protected", "Error message", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                }
 
            }
          
        }

Thanks Sir.

Answers (5)