Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


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
VB.NET
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
Posted
Updated 28-Sep-18 15:06pm
v2

1 solution

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 = From CS In DB.CityLookups Order By CS.CityName


"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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900