如何使用复选框删除GridView中的多行,删除的数据应存储在库存表中 [英] How to Delete multiple Rows in GridView using Check box and deleted data should store in stock table

查看:80
本文介绍了如何使用复选框删除GridView中的多行,删除的数据应存储在库存表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用SQL SERVER 2005的ASP.Net(C#)中有一个Webform,在这里我想使用Checkbox删除GridView中的多行,我在搜索时发现了很多示例,它可以正确删除,但我也想在选择时复选框,已删除数量应存储在库存表中.假设我要从系统中删除一些硬件,在下拉列表中选择systemName时,它将在gridview中显示系统中所有的硬件安装,同时在复选框中选中并按Delete键,则应从gridview中删除并在库存中插入数量.因此,我该怎么办. anyvody可以帮助我解决此问题.
我已经使用了下面显示的一些代码


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


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();
    }



注意:-最好得到代码,

在库存表中,我的列为CatId,PId,Qty



Note:- Better if will get the code,

In stock table i have column CatId, PId, Qty

推荐答案


您可以为删除后"向SystemConfiguration表写入触发器,该触发器将自动在您需要的表中插入一条记录
Hi,
You can write a trigger to SystemConfiguration table for ''after delete'', which will automatically insert a record in which ever table u need


嘿,
您可以使用SqlBulkCopy类做到这一点
以下链接将帮助您
http://msdn.microsoft.com/en-us/library/system. data.sqlclient.sqlbulkcopy.aspx [ ^ ]
祝你好运
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


这篇关于如何使用复选框删除GridView中的多行,删除的数据应存储在库存表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆