使用文本框中的多个值搜索数据库 [英] Search on database using mutiple values from textbox
本文介绍了使用文本框中的多个值搜索数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三个文本框-滚动,注册,名称;还有一个提交按钮
现在,用户可以在文本框中提供输入内容
可能有几个文本框为空白.因此,空字符串(")进入where子句.
我想要一种选择查询,它应根据用户输入的值搜索数据库中的数据,并忽略未输入的值
I have three text boxes - roll,registration,name ;and a submit button
Now the user can provide input in the text boxes
there is a possibility of few textboxes being blank. So a empty ( "" ) string goes into the where clause.
I want a select query in such a way that it should search the data in database according to the values entered by the user, and ignore the the values not entered
推荐答案
然后,您需要调整select
子句以忽略空白条目.一些if语句和StringBuilder
应该可以解决问题.
Then you need to adjust yourselect
clause to ignore the blank entries. A few if statements and aStringBuilder
should do the trick.
StringBuilder select = new StringBuilder("SELECT * from datatable WHERE");
if (!textRoll.IsEmpty && textRoll != "")
{
// add the details for the roll being present
// and the parameter value(s) for the query
}
...
// repeat for the other fields
这篇关于使用文本框中的多个值搜索数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文