Search function

fikri

New member
Joined
Jan 18, 2018
Messages
2
Programming Experience
Beginner
Hello to all. I am newbie here so I would like someone help me with my first project.

I need to make a search in the grid view depending of multiple fields criteria.
I have 4 ftexboxes: textbox1 textbox2, textbox3 and textbox4.
I have one gridview with data from access database. This is ok.
Problem is search criteria. I need to show only those records what I entered in textboxes.
For example:

textbox1 is filter for column1
textbox2 is filter for column2...etc.

Now is working when I change each textbox text separatelly.
But i need to do it on this way that I can fill multiple texboxes... and filter still must works.
Problem is when some textbox is empty, in that case no one record matches and grid is empty.
Is it possible to ignore texbox which has empty string?

I hope I explained it good, english is not my primary language.

Thanks
 

fikri

New member
Joined
Jan 18, 2018
Messages
2
Programming Experience
Beginner
Hello. Thanks for reply but I am not sure that I understand you. Do you have any detailed example? Thanks
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,169
Location
Sydney, Australia
Programming Experience
10+
A filter is just a String. You know what you need your String to look like so write it down and then work out how to build that. You know that you have four TextBoxes. As I said, you can either:

1. Ignore the TextBoxes that are empty and only add a condition for those that aren't. It should be obvious that that will require an If statement, i.e. IF the TextBox is not empty THEN add the appropriate condition to the filter String.

or

2. Add a pair of conditions for each TextBox. I've shown you what those conditions look like. You just need a line of code for each TextBox that will add the appropriate conditions to your filter String.
 
Top Bottom