如何使用datagridview复选框列来检查要插入sql server数据库的所需记录 [英] how to use datagridview checkbox column to check the desired records to insert into sql server database

查看:47
本文介绍了如何使用datagridview复选框列来检查要插入sql server数据库的所需记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我是新手,还在学习。

我打算使用datagridview复选框列检查所需的要将
插入sql server数据库的记录,我想要的过程是在检查了一些checkBox后再按一下按钮执行插入查询。我想要保存(插入)到数据库中的值来自datagridview中的选定行。

如何执行代码? (请举例说明。)



请帮助我,我很感激每一个答案。



谢谢。

Hello,

i'm newbie and still learning.
i'm going to use datagridview checkbox column to check the desired records to insert
into sql server database, the process i want is after checking some of the checkBoxes and then do the insert query on a button click. The values i want to save (insert) into database is from selected row in datagridview.
how to do the code? (with example please).

please kindly help me, I appreciate every answer.

thank you.

推荐答案

您可以使用for循环datagridview行,并在循环内部使用if检查复选框是否为true,如果是,则执行插入查询。



改进:



You can simply loop the datagridview row using for, and inside the looping, use if to check if the checkbox is true, if it is then execute your insert query.

Improve :

for (int i = 0; i <= this.dataGridView1.Rows.Count - 1; i++)
{
    if ((bool)this.dataGridView1.Rows[i].Cells["ColName"].Value == true)
    {
        //your query execution here
    }
}





不确定但值得一试。



not sure but, worth trying.


这篇关于如何使用datagridview复选框列来检查要插入sql server数据库的所需记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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