user1131661
user1131661

Reputation: 229

Filter number in a DataView using RowFilter in C#4.0

I'm trying to filter my DataView DataSet using RowFilter.

I would like to perform a like statement on an Integer column

So something like this:

myDataView.RowFilter ="ID LIKE %1%";

This works fine for string columns but I receive an error when trying this will integers. I receive the follow error: Cannot perform 'Like' operation on System.Int32 and System.Int32.

Anyway of doing a LIKE statement on numbers?

Thanks in advance.

Upvotes: 3

Views: 7299

Answers (3)

bdkdavid
bdkdavid

Reputation: 223

This gets the specific item requested. It works on one item exactly

"Convert(DataGridColumnName, 'System.String') LIKE '%" & txtBox.Text & "%' "

Example 1:

 DV.RowFilter = "Convert( TicketNo , 'System.String') LIKE  '%" + txtTicketNo.Text + "%'

This only receive the exact ticket number if you want to retreive items like that start with it receives all items that start with

Example 2:

DV.RowFilter = "Convert( TicketNo , 'System.String') LIKE  '" + txtTicketNo.Text + "%' ";

In Theory the first Example should be looking in the whole string and searching for matches. The one that I have done does not do that maybe I had missed something,

Upvotes: 0

Aten
Aten

Reputation: 49

It worked with me:

"Convert(DataGridColumnName, 'System.String') LIKE '%" & txtBox.Text & "%' "

Upvotes: 4

4b0
4b0

Reputation: 22323

You must convert using cast.

"Convert(ID, 'System.String') LIKE  %1%"

Upvotes: 2

Related Questions