使用datagridview中的复选框列,根据多个行选择更新数据库 [英] Update database based on the multiple selection of rows using check box column in datagridview

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

问题描述





我有一个带有复选框列的datagridview作为其中的第一列。



我希望用户选择多个复选框,在按钮单击事件上,应根据datagridview第二列的值执行SQL更新查询。



示例查询:更新表设置确认= 0其中empname in('Mike','Jack')



Mike和Jack是用户使用复选框列选择的。



请为我推荐一个解决方案。



在此先感谢

Hi,

I have a datagridview with a check box column as the first column in it.

I want the users to select multiple check boxes and on a button click event, an SQL update query should be executed based on the values from the second column of the datagridview.

Example query : Update table set confirm=0 where empname in ('Mike','Jack')

Mike and Jack are the selections by the user using the check box column.

Please suggest me a solution for this.

Thanks in advance

推荐答案

please describe your problem properly


大家好,



我终于得到了解决方案。





Hi All,

I got the solution finally.


for (int i = 0; i < dtgrdUnconfirm.Rows.Count; i++)
                {
                    DataGridViewCheckBoxCell clmSelect = new DataGridViewCheckBoxCell();
                    clmSelect = (DataGridViewCheckBoxCell)dtgrdUnconfirm.Rows[i].Cells[0];                 
                    if (clmSelect.Value != null &&
                           Convert.ToBoolean(clmSelect.Value) == true)
                    {
                        data += (dtgrdUnconfirm.Rows[i].Cells[6].Value.ToString())+",";                        
                    }                    
                }
                data = data.TrimEnd(',');                
                if (lstbxUnconfirm.SelectedItem.ToString() == "ID")
                {
                    updatesql = "update tablename set Confirmed=0 where id in (" + data + ")";
                }


这篇关于使用datagridview中的复选框列,根据多个行选择更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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