This type of Filtering possible?

  • Thread starter Thread starter Chris Botha
  • Start date Start date
C

Chris Botha

The DataTable has a column containing integers.
Filtering it as "Where ColName=12" filters fine.
Here is the problem. I want to filter the integer column using "Like". For a
string column the following will work "Where StrColName Like '12%'". I
need the same effect on the integer column.

Thanks for any pointers.
 
In you where clause, convert the integer to a string and then you can use
the LIKE clause. Valid function to use in the filter string are fully
documented in the .NET framework.
 
Yes, use CONVERT expression keyword (see DataColumn.Expression .net help)
 
My mistake, I should not have used "Where" in my examples for the RowFilter
string, suggesting a select statement, in which case I can use the CAST or
CONVERT functions.

In my case the data is selected into the DataTable already and I can't
change the select statement (don't have a lot of control over that part
unfortunately). So the table contains an integer column and the requirement
is to filter on the first number of digits entered.
The best that I can come up with at the moment is to loop through the table
and compare the column of each row (after converting it to a string) to the
digits. This happens as the user is entering digits, which is a bit slow if
there are many rows. Changing the RowFilter of the DataView for a string
field on the fly as the user types (using LIKE), is blinding fast.
 
You did not carefully read my response.

I was suggesting using the conversion function in the filter clause.
 
Right, thanks, exactly what I was looking for.

Miha Markic said:
Yes, use CONVERT expression keyword (see DataColumn.Expression .net help)

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Chris Botha said:
The DataTable has a column containing integers.
Filtering it as "Where ColName=12" filters fine.
Here is the problem. I want to filter the integer column using "Like". For
a
string column the following will work "Where StrColName Like '12%'". I
need the same effect on the integer column.

Thanks for any pointers.
 
If it's an integer, could you not just do something like "between 120000 and 129999" or
">= 120000 and < 130000" to get all of the ones that begin with 12?

Of course, this method won't work if you really want to see 12, 120-129, 1200-1299, etc

Beverley
 
Thanks, it is working with the Convert now.

Marina said:
You did not carefully read my response.

I was suggesting using the conversion function in the filter clause.
 
Hi Beverly,

I was a bit knocked over in the beginning until I read the help on the
DataColumn.Expression (thanks to Miha and Marina) and it works, pretty
powerful. For an integer column called IntCol an example would be
TheView.RowFilter = "CONVERT(IntCol, 'System.String') Like '" & theText &
"%'"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top