Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a Webform in ASP.Net(C#) using SQL SERVER 2005, In this I was looking to Delete multiple Rows in GridView using Checkbox,I found many example while searching, Its deleting properly but I also want, while selecting checkbox,Deleted Quantity should store in Stock table. Suppose i want to delete some hardware from the system, while selecting systemName in dropdownlist it display all the hardware install in system in gridview, while selecting in checkbox and press delete button it should delete from the gridview and insert quantity in the stock. So for that, what Should I do. Can anyvody will help me to resolve this problem.
I have used Some code shown below


C#
protected void BtnRemove_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in dgvRemoveHware.Rows)
        //for (int i = 0; i < dgvRemoveHware.Rows.Count;i++)
        {
            //CheckBox cBox = dgvRemoveHware.Rows[i].Cells[0].Text;
            CheckBox cBox = (CheckBox)row.FindControl("CheckBox1");
            if (cBox.Checked)
            {
                int ConferenceId11 = Convert.ToInt32(dgvRemoveHware.DataKeys[row.RowIndex].Values[0]);
                int CatId11 = Convert.ToInt32(dgvRemoveHware.DataKeys[row.RowIndex].Values[1]);
                int PId11 = Convert.ToInt32(dgvRemoveHware.DataKeys[row.RowIndex].Values[2]);
                int Qty11 = Convert.ToInt32(dgvRemoveHware.DataKeys[row.RowIndex].Values[3]);
                ConnectionStr();
                con.Open();

                SqlCommand cmd = new SqlCommand("Delete from SystemConfiguration where ConfId='" + ConferenceId11 + "'",con);
                //cmd.CommandText = "Delete from SystemConfiguration where ConfId=" + ConferenceId11;
                cmd.ExecuteNonQuery();
                //cmd.Connection = con;
                //obj.executeDML("Update Stock set TotalQty=TotalQty + '" + Qty11 + "' where CatId='" + CatId11 + "' and Pid= '" + PId11 + "'", false, con);
                //obj.setDataTable("Select CatId,PId from SystemConfiguration where ConfId='" + ConferenceId11 + "'",false,con);
                SqlCommand cmdA = new SqlCommand("Select CatId,PId,Qty from SystemConfiguration where ConfId='" + ConferenceId11 + "'", con);
                //SqlDataReader dr = cmdA.ExecuteReader();
                //while (dr.Read())
                //{
                //    CatId11 = dr[0].ToString();
                //    PId11 = dr[1].ToString();
                //    Qty11=dr[2].ToString();
                //}
                cmdA.ExecuteNonQuery();



                //SqlCommand cmd1 = new SqlCommand("Update Stock set TotalQty=TotalQty + '" + Qty + "' where CatId='" + CatId + "' and PId= '" + PId + "'", con);
                //cmd1.ExecuteNonQuery();
                con.Close();

                //con.Open();
                //int ConferenceId = Convert.ToInt32(dgvRemoveHware.DataKeys[row.RowIndex].Value);
                //SqlCommand cmd2 = new SqlCommand("Delete from SystemConfiguration where ConfId=" + ConferenceId, con);
                //int numberDeleted = cmd2.ExecuteNonQuery();
                //LblMsg.Text = numberDeleted.ToString() + " Hardwares were deleted";
                con.Close();
                //BindGrid();
                BtnRemove.Visible = true;
                BtnCancel.Visible = true;
            }
        }
        BindHardware1();
    }


Note:- Better if will get the code,

In stock table i have column CatId, PId, Qty
Posted
Updated 3-Apr-12 22:51pm
v2

Hi,
You can write a trigger to SystemConfiguration table for 'after delete', which will automatically insert a record in which ever table u need
 
Share this answer
 
Hey,
u can do this using SqlBulkCopy Class
following Link will help u
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx[^]
best Luck
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900