如何征用被核对清单框过滤的多个记录 [英] how to enlist multiple records filtered by checkedlistbox

查看:51
本文介绍了如何征用被核对清单框过滤的多个记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有数据网格视图和选中的列表框.我想从数据库项目中填充检查列表框,我想使用检查列表框的项目创建过滤器,这意味着通过检查检查列表框的项目来填充数据网格视图,现在的问题是数据网格视图 仅显示一个记录对应于选中的项目,但是如果选中了多个复选框,则不显示多个记录.

have a data grid view and checked list box. checked list box is populated from database items i want create filter using checked list box's items means to populate data grid view by checking checked list box's items now the problem is that data grid view show only only one record corresponds to checked item but does not display multiple records if multiple checkbox items are checked.

SqlConnection connection = new SqlConnection();
        connection.ConnectionString = @"Data Source=DESKTOP-50ME4GC\SQLEXPRESS;Initial Catalog=autolab;Integrated Security=True";
        if (pn.CheckedItems.Count != 0)
        {
            // If so, loop through all checked items and print results.  
            string s = "";
            int x;
            for (x = 0; x <= pn.CheckedItems.Count - 1; x++)
            {
                s = s + pn.CheckedItems[x].ToString();
            }
            connection.Open();
            SqlCommand cmd = new SqlCommand("SELECT *  from test_report  inner join tests  on test_report.test_name = tests.Test_name WHERE tests.Test_name IN ('" + s + "') ", connection);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);


            DataTable tbl = new DataTable();


           adapter.Fill(tbl);


            dt.DataSource = tbl;


            connection.Close();

        }


推荐答案

尝试一下.

      for (x = 0; x <= pn.CheckedItems.Count - 1; x++)
      {
         s += (x > 0) ? ", '" : "'";
         s = s + pn.CheckedItems[x].ToString();
         s += "'";
      }

      string cmd = "SELECT *  from test_report  inner join tests  on test_report.test_name = tests.Test_name WHERE tests.Test_name IN (" + s + ") ";


这篇关于如何征用被核对清单框过滤的多个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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