Multi Criteria Filter in Windows Form

Hi Folks,

Here again just trying to point to the right direction. I have a Windows Form App created in Visual Basic.NET 2008 very simple composed of a few forms and reports. I want to make my filters to my data in SQL a little more dynamic. I can create a simple filter instance using the wizards in Visual Studio and creating custom queries but now I want to use multiple criteria. What is the best approach for this? A new form that you can use to select and filter data from? How do I do that? Any light is appreciated.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Can't you just simply use an SQL Stored Procedure and pass parameters into it, then bind the results? This way you can filter / order the results however you wish.
Another thing you can do if you want to is filter the results by creating new List(Of Object) and comparing your filters, if they match, newlist.Add(Object). This would mean you would not have to hit the database again. You can also do this for sorting using the Implements IComparer(Of Object).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
angelarmandoAuthor Commented:
Hi blandyuk,

Both solutions sounds feasable. I have no problems hitting the DB again. Which is better to learn. Creating SP in SQL or the New list approach? Any links that you can share?
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Jorge PaulinoIT Pro/DeveloperCommented:
I normally use the SP with optional paramenters. Then I open a new form (or in the existing one if there is space available) and give the user the oportunity to choose.
angelarmandoAuthor Commented:
Hi jp,

Right. That is a great idea. Now in my case the SQL side is very restricted (the DBAs are very and to maintain those might be a problem. How about the second choice? the new list (of object)? Any link to that approach?

Thanks guys for the leads BTW,

Depends how you have coded your project, I'm assuming you have created your Objects and other layers:

Object Layer
Data Layer
Business Layer

I have a "FilterEngine.vb" class in my Busines Layer which deals with object filtering. Example below:
Public Shared Function PersonFilterByTitle(ByRef listP As List(Of Person), ByVal title As String) As List(Of Person)
	Dim newList As New List(Of Person)

	For Each item As Person In listP
		If item.Title = title Then
		End If
	Next item

	Return newList
End Function

Open in new window

Jorge PaulinoIT Pro/DeveloperCommented:
I don't work that way and I always do using the SP.
If you do not use ORP then a simple code example to load results by applying a filter.

Dim dbadp as new sqldataadapter("Select ... Where columnname like '%" & txtsearch.text & "%'", connectionstring)

dbadp.fill(dTable) 'dTable is a datatable

DataGridView1.DataSource = dTable
angelarmandoAuthor Commented:
Thank you guys... I will look into that.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.