Student Student - 2 years ago 69
SQL Question

VB.NET MYSQL How to implement a more efficient search program?

In my database there are 3 column which is Name, Age, Gender.
In the program, I only want to use 1 search button. When the button is clicked, the program determine which 3 of the textbox has input and search for the right data.

How do you work with the query? For example if Name and Gender has text, the query :


Select * from table Where (Name = @name) AND (Gender = @gender)

And when only name is entered, I only query for the name. Must I check textbox by textbox whether there is user input and then write multiple query for each of them? Or is there a better way to do this?

Answer Source
Select * from table 
Where (Name = @name OR @name is Null) 
  AND (Gender = @gender OR @gender is Null)

it should be one query

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download