Saturday, May 31, 2014

How to search a record in datagridview in VB.Net

In the post i am going to show the various method available to search a record in datagridview.
Before that just take a look at LIKE Clause :
The SQL LIKE clause is used to compare a value to similar values using wildcard operators.
Means if you search for 'a' then it will show all the records starting with letter 'a'

A Normal Search Example :

Search using Like Clause

Ok so lets start with a simple one :
After adding a textbox & datagridview to your form ,double click your textbox 
and paste the following code:
Me.Your binding name.Filter="Your column name = ' " & Your search textbox & " ' "

Or if your want you can use this one(Using LIKE Clause) :Me.YourBindingSourceName.Filter = "[Column Name] like '*" & TextBox Name & "*' "

Tip : If you are using SQL Server then replace * with %
Note : These methods working only if you have added Binding source in our program.

Watch Video with an example :


Post a Comment