如何使用文本框和组合框进行搜索 [英] How to search using a textbox and a combobox

查看:93
本文介绍了如何使用文本框和组合框进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用vsstudio 2010(c#,windowsforms)..



tblcustomer ..

[custno,姓名,年龄,性别,地址]



我做的示例代码工作正常,但只能通过[name]搜索。我想通过组合框中的选定项目进行搜索|过滤。我的组合框中的项目是我的表格列名.. TIA ..



我尝试了什么:



using vsstudio 2010 (c#, windowsforms)..

tblcustomer..
[custno, name, age, gender, addr]

the sample code i make works fine but it only search through by [name]. i want to make a search|filter by the selected items in my combobox. items in my combobox is my column names of table.. TIA..

What I have tried:

this.tblcustomerBindingSource.Filter = "name like '%" + textBox1.Text + "%' ";

推荐答案

试试这样



try like this

string column = comboBox1.Text;
           string text = textBox1.Text;
           string filter = string.Format("{0} like '%{1}%'", column, text);
           this.tblcustomerBindingSource.Filter = filter;



注意:请注意验证。


Note: Take care of the validations.


这篇关于如何使用文本框和组合框进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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