基于Combobox的搜索查询的构建 [英] Fomration of Searching Query on the basis of Combobox
问题描述
我已经为搜索目的制作了一个表格。
其中
1。 8个Combobx,8个值/项目(表格列名)
2。一个TextBox
3。另一个带两个选项的Combobx(AND / OR)
以上3行组在我的表格中是八次。
i还有一个带有六个选项的清单框
现在我要进行搜索查询。
这里是查询
I have made a form for searching purpose.
where
1. eight Combobx with 8 Values/Items (table Column Names)
2. one TextBox
3. another Combobx with two option (AND/OR)
the above 3 line group is eight time in my forms.
i have also place a checklist box with six option
now i am going to make searching query.
here is the query
string SearchQuery = "Select * From Hadiths_old Where Baab_Id < 100 =" + BookSelection + AndOrQuery ;
这里BookSelection查询片段形成,这是核对表框项目选择的基础之一
here BookSelection Query Fragment Formation, this is one the basis of checklist box item selection
string BookSelection = "";
if (clbBooksName.GetItemChecked(0) == true)
{
BookSelection = "OR Hadith_Book_Number = 1";
}
if (clbBooksName.GetItemChecked(1) == true)
{
BookSelection = "OR Hadith_Book_Number = 2";
}
if (clbBooksName.GetItemChecked(2) == true)
{
BookSelection = "OR Hadith_Book_Number = 3";
}
if (clbBooksName.GetItemChecked(3) == true)
{
BookSelection = "OR Hadith_Book_Number = 4";
}
if (clbBooksName.GetItemChecked(4) == true)
{
BookSelection = "OR Hadith_Book_Number = 5";
}
if (clbBooksName.GetItemChecked(5) == true)
{
BookSelection = "OR Hadith_Book_Number = 6";
}
现在为Combox of Column和AND / OR运算符。我真的卡住了
8个组合框值和一个文本框然后另一个组合框有两个值(和/或)
i尝试进行此查询
Now for Combox of Column and AND/OR Operator. I am really stuck
8 combobox values with one text box and then also another combobox with two values (and/or)
i try to make this query
if(!String.IsNullOrEmpty(tbSearch1.Text) && cbColumn1.SelectedIndex ==0 && cbOperator1.SelectedIndex==0)
{
AndOrQuery = "AND Hadith_Arabic ="+ tbSearch1.Text + "AND";
}
可能会有效但我真的很担心如果我使用这种技术然后我需要赚很多条件可能是50或100条件,这是不可能的。请在这里帮忙。
如何形成查询?
may be this will work but i am really worry if i use this techniques then i need to make lot of condition maybe 50 or 100 condition which is not possible. please help here.
how to form query??
推荐答案
你的代码是一场噩梦。首先,它使用ifs而不是开关。其次,字符串mashing SQL总是很糟糕。如果你停下来看看你的代码,你正在寻找书号n + 1,其中n是被检查的项目。这个逻辑很容易在循环中解决,创建一个要查找的项目列表,您可以将其作为XML传递给存储过程。
Your code is a nightmare. For a start, it's using ifs instead of a switch. Second, string mashing SQL is always bad. If you stop and look at your code, you are looking for booknumber n+1 where n is the checked item. That logic is pretty easy to work out in a loop, creating a list of items to look for, which you can pass in to a stored proc as XML.
这里的要求似乎非常复杂,但不要担心我想说创建一个存储过程(因为你在这里使用SQL命令)将该查询中的所有参数添加为可选
然后在存储过程中根据值添加条件。我认为这会更容易。
谢谢
Raj
Hi,
It seems very complex requirement here but don't worry I would like to say create a stored procedure (as you are using SQL command here) add all the parameter in that query as optional
and then in stored procedure according to value add the condition. I think that will be more easy.
Thanks
Raj
这篇关于基于Combobox的搜索查询的构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!