如何编写查询查询。 [英] how to write the query for searching.
问题描述
大家好,
我有一个来自列表框,我的列表框显示客户名称和选择模式是多个。我选择3项或更多项目然后点击搜索按钮。
单项选择工作正常,显示数据正确。但我的列表框查询中的一个或多个选择不起作用。如何编写查询。?
数据库客户端名称字段是否存在。
如何使用多个客户端名称搜索数据单列。我将给出client_name =''san,jhone,dev''然后显示这些客户端名称的相关数据。
如何显示请帮助我
Hi All,
I have one from with list box, my listbox shows client names and selection mode is multiple. am select the 3 or more items then click on search button.
single selection is working fine and display data correct. but 1 or more selection in my list box query is not working. how to write the query.?
in database client-name field is there.
how to search the data single column with multiple client names.i.e am given to client_name=''san,jhone,dev'' then display the related data on these client-names.
how to display please help me
推荐答案
首先准备字符串变量,其中包含listbox中用逗号(,)分隔的所有选定值,并带有以下代码
First prepare string variable which contains all selected values in listbox separated by comma(,) with following code
string selecteditems = "";
for (int i = 0; i < listBox1.Items.Count; i++)
{
if (listBox1.GetSelected(i))
{
selecteditems += "'"+listBox1.GetItemText(listBox1.Items[i])+"',";
}
}
selecteditems = selecteditems.Remove(selecteditems.Length - 1);
现在写你的选择查询为
从客户服务中选择* client_name in(+ selecteditems +)
这肯定会帮助你..
很开心。
如果它帮助你忘记点击接受ans并投票支持它。
享受:)
Now write ur select query as
" Select * from clienttable where client_name in ("+ selecteditems +")"
this will surely help u..
hav a great time.
If it helps u dnt forget to click on accept ans and vote for it.
enjoy :)
或者,将你的列表框绑定设置DataValueField
属性为client_id
和DataTextField
为CLIENT_NAME
。
您可以发送Client_ID'[假设数据库中存在该列]作为逗号分隔值,在select查询中您可以写入
Alternatively, bind your listbox with settingDataValueField
property asclient_id
andDataTextField
asclient_name
.
You can send the Client_ID''s [assuming that column is present in your database] as comma separated values and in select query you can write
select client_id in (1,2,3) -- where 1,2,3 are selected client ids.
这篇关于如何编写查询查询。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!