如何过滤列表视图记录 [英] how to filter list view records

查看:54
本文介绍了如何过滤列表视图记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码将列表视图中的记录插入数据库..它工作正常,它将列表视图中的所有记录插入到数据库中。但我如何使用foreach循环过滤记录。实际上我只想在列表视图的第五列中插入状态为预订的记录。状态列位于列表视图的第五个数字中。它不在数据库中。希望你理解我的问题。





提前致谢..



i am using below code to insert records from list view to database.. it is working fine it inserts all the records from list view to database. but how can i filter records using foreach loop. actually i want to insert only that records which have status ''Booked'' in list view''s fifth column. Status column is in fifth number of list view. and it is not in the database. Hope you understand my question.


Thanks in advance..

foreach (ListViewItem li in listView1.Items)
           {
               OleDbCommand cmd = new OleDbCommand("insert into bookings (code,client_name)values('" + li.SubItems[0].Text + "','" + li.SubItems[1].Text + "');", con);
               cmd.ExecuteNonQuery();

           }

推荐答案

如果条件在for循环的开头如下,那么



Have if condition in the beginning of for loop as below

foreach (ListViewItem li in listView1.Items)
           {
               if (li.SubItems[0].Text=="Booked")
               {
               OleDbCommand cmd = new OleDbCommand("insert into bookings (code,client_name)values('" + li.SubItems[0].Text + "','" + li.SubItems[1].Text + "');", con);
               cmd.ExecuteNonQuery();
             }
           }


这篇关于如何过滤列表视图记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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