如何通过多组合框搜索 [英] How to search by multi comboboxs

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

问题描述

Halo Guys



我在Visual Basic中有一个问题(Microsoft Visual Basic 2013)



我正在使用TextBox和CompoBox搜索数据库中的表(注意使用LINQ to sql)



我在国家/地区的数据库中有一个表名称和另一个城市名称表和另一个国籍表(每个包括姓名和号码)



我的意思是国家表:

Halo Guys

I have a question in the Visual Basic (Microsoft Visual Basic 2013)

I am searching a table in the database using more than the TextBox and CompoBox (Note that LINQ to sql is used)

I have a table in the database of country names and another table of city names and another table of nationalities (and each one consists of name and number)

I mean the table of countries :

Name                     Number
UK                         1
France                     2     ... etc



和城市表:


And the table of the cities :

Name                     Number
London                     1
Paris                      2     ... etc



和国籍:


And the nationalities:

Name                     Number
British                     1
French                     2     ... etc





所有桌子都用Combobox填写

名称:Combibox.DisplayMember

和数字Combibox.ValueMember

Combibox.selectedValue = -1



我有Windows表单

文本框名称

Combobox性别

Combobox for country

Combobox for cities

Combobox Nationalities



问题是:我想在表格中搜索特定记录



但是,当我选择性别和国家,国籍和城市时(全部在一起)很好我有结果



但是当我不选择它们(compubexs)或其中一个compboxes没有执行搜索时它显示错误





有什么方法可以解决这个问题吗?或者如何解决这个问题?



此外,没有必要选择任何组合框,我的意思是有时我想只搜索名字,我想要查询这种搜索



提前谢谢大家



我尝试过的:



这就是我填充组合框的方式,国家和国籍是一样的



All tables are filled in Combobox
For names: Combibox.DisplayMember
And for numbers Combibox.ValueMember
Combibox.selectedValue = -1

And I have Windows form has
Textbox for the name
Combobox for gender
Combobox for country
Combobox for cities
Combobox Nationalities

The question is: I want to search for a specific record in the table

However, when I choice the gender and country and nationality and city (All together) are fine I have the result

But when I do not choice them ( the compubexs) or one of the compboxes does not perform the search and it show error


Is there any way to solve this problem? or how to solve this problem?

Also, it is not necessaryto choice any of the combobox , I mean some times I want to search just by names and I want the query of this kind of searching

Thank you all in advance

What I have tried:

This is how I fill the comboboxe and the countries and the nationalities are the same

Sub FillComb_Cities()
        Comb_City.DataBindings.Clear()
            Dim Cities = From CS In DB.CityLookups Order By CS.CityName
            Comb_City.DataSource = Cities
            Comb_City.DisplayMember = "CityName"
            Comb_City.ValueMember = "CityId"
            Comb_City.SelectedValue = -1
End Sub

推荐答案

嗨。



我会尝试为搜索创建一个PRE条件图层。



与精选案例类似,您只能通过搜索参数的金额调用搜索。





Hi.

I would try to create a "PRE Condition" Layer for the Search.

Like a Select Case, where You calling only the Search by the "amount" of the Search Parameters".


Select Case True
 
Case IsNothing Name = True
'Do the LINQ request here for "Only Name"

Case IsNothing Surname = True
'Do the LINQ request here for "Only Name"

Case IsNnothing Surname AndAlso IsNothing Name
'Do the Linq with "Multiple Conditions"

End Select





当然请使用更精致的条件...





And of Course please use more refined Conditions...

Quote:

Dim Cities =来自CS在DB.CityLookups中按CS.CityName排序

Dim Cities = From CS In DB.CityLookups Order By CS.CityName





IsNothing = Tru e不是那么Sufisticated ......;



在LINQ中使用Where选择任何等等什么让你有资格拥有mor搜索结果精确...



cu来自汉堡的Zui



"IsNothing = True" is not so Sufisticated... ;)

Use in the LINQ "Where" "Select" "Any" etc. what gives You the Abitilty to have mor refined results for the Searches...

c.u. Zui from Hamburg


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

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