Bindingsource .Filter using LIKE and numeric fields
Hi !
I try filtering Bindingsource using LIKE operator for a numeric field,but I can't resolve it.
id - numeric field
name - text field
Code:
bsrc.Filter = " CStr(ID) LIKE '%"+txtSearch.text+"%' OR name LIKE '%"+txtSearch.text+"%'"
I got error : "The expression contains undefined function call cstr()"
Thanks.
Re: Bindingsource .Filter using LIKE and numeric fields
So, you tried to use the Filter property and it didn;t work the way you wanted it to? The first thing you should have done was go to the MSDN documentation for that property. Here's a quote from that topic:
Quote:
If the underlying data source is a DataSet, DataTable, or DataView, you can specify Boolean expressions using the syntax documented for the DataColumn.Expression property.
The underlined part is a link, so you would have clicked that link and that would have taken you to that topic, which explains all about the valid syntax.
Re: Bindingsource .Filter using LIKE and numeric fields
Quote:
Originally Posted by jmcilhinney
So, you tried to use the Filter property and it didn;t work the way you wanted it to? The first thing you should have done was go to the MSDN documentation for that property. Here's a quote from that topic:The underlined part is a link, so you would have clicked that link and that would have taken you to that topic, which explains all about the valid syntax.
Thanks jmcilhinney !
I've read your suggestion.It seems I have to create another column,string type and use filter with,but I don't like this because if I have 100 numeric fields and I need to buid a complex filter,do I have to duplicate each ?
Code:
Dim cstrID = New DataColumn
With cstrID
.DataType = System.Type.GetType("System.String")
.ColumnName = "strID"
End With
wTbl.Columns.Add(cstrID)
......................................
bsrc.Filter ="strID LIKE .... "
Thanks !
Re: Bindingsource .Filter using LIKE and numeric fields
I can't see why you would be using LIKE on numeric columns anyway? If this is the type of column for which you might want to do that then it should be a text column anyway. An example is a column containing phone numbers. It might contain nothing but numbers but it should be a text filed none the less.
Re: Bindingsource .Filter using LIKE and numeric fields
Quote:
Originally Posted by jmcilhinney
I can't see why you would be using LIKE on numeric columns anyway? If this is the type of column for which you might want to do that then it should be a text column anyway. An example is a column containing phone numbers. It might contain nothing but numbers but it should be a text filed none the less.
Thanks jmcilhinney. You're right,I 'll use only one numeric field and one new column,I want to extend search for ID (autoincrement field).Thanks !