如何更新数据库中的多个行 [英] how to update mutiple rows in databse

查看:85
本文介绍了如何更新数据库中的多个行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在C#中的一个项目中工作.在其中显示网格视图中的记录.
在gridview列中,我在gridview列中使用单选按钮.

我希望该用户可以选择多个行的单选按钮.
然后他将保存该记录,所以我想知道,请告诉我一个代码,当我保存代码时,将减少消耗的时间.

现在我在存储过程中使用插入查询一次插入一条记录
因此在上述情况下将使用什么代码.

请告诉我.

Hello Every One,

I am working in a project in C#. In Which I am show records in gridview.
In a column of gridview i use a radio button in a column of gridview.

I want that user may be select more than one row''s radio buttons.
and after that he will be save that records so i want to know that please tell me a code by which when i will save recirds then less time will be consume.

now i am using an insert query in stored procedure to insert a single record at a time
so in the above situation what code will be use.

please tell me.

推荐答案

您可以使用此

You can use this

protected void btnSubmit_Click(object sender, EventArgs e)
        {	
	    
            foreach (GridViewRow gr in GridView1.Rows)
            {
                Label lbl = (Label)(gr.Cells[8].FindControl("Label4")); 
                RadioButton R1 = (RadioButton)(gr.Cells[7].FindControl("RD1")); 
                RadioButton R2 = (RadioButton)(gr.Cells[7].FindControl("RD2"));
                RadioButton R3 = (RadioButton)(gr.Cells[7].FindControl("RD3"));
                DropDownList ddL = (DropDownList)(gr.Cells[6].FindControl("DropDownList1"));
                HiddenField dd1 = (HiddenField)gr.Cells[6].FindControl("lblddl");
                if (R2.Checked == true)
                {
                    if (dd1.Value != "")
                    {
                        {
				//update query		
                        }
                        
                    }
                }

                if (R3.Checked == true)
                {
                    if (dd1.Value != "")
                    {
                        {
				//update query		
                        }
                        
                    }
                }

            }


这里lbl存储在条件更新查询中使用的ID.


Here lbl stores the ID where is used in the update query for condition.


protected void btnSubmit_Click(object sender, EventArgs e)
        {	
	    
            foreach (GridViewRow gr in GridView1.Rows)
            {
                Label lbl = (Label)gr.FindControl("Label4"); 
                RadioButton R1 = (RadioButton)gr.FindControl("RD1"); 
                
                RadioButton R3 = (RadioButton)gr.FindControl("RD3");
                DropDownList ddL = (DropDownList)gr.FindControl("DropDownList1");
               
                if (R1.Checked == true)
                {
                    if (dd1.Value != "")
                    {
                        {
				//update query		
                        }
                        
                    }
                }
 
                if (R3.Checked == true)
                {
                    if (dd1.Value != "")
                    {
                        {
				//update query		
                        }
                        
                    }
                }
 
            }


这篇关于如何更新数据库中的多个行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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