Share This!

Tuesday, October 18, 2011

BindingSource filters: Partial Match on Int Columns

Recently I had to do a filter on a DataGridView and needed the dataset to filter on a partial match of an integer column.   It took me a few minutes to figure this out...

if (!string.IsNullOrEmpty(ticket))
{
   filter = string.Format("Convert(ID,'System.String') like '%{0}%' ", ticket);
}
This gives a filter line that looks a lot like
"Convert(ID, 'System.String') like %123%"
 Which will show all rows where the column ID partially matches 123.


...

Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Contact Us

Name

Email *

Message *