-
Aug 26th, 2007, 02:21 AM
#1
Thread Starter
Lively Member
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.
Last edited by ionut_y; Aug 26th, 2007 at 02:27 AM.
-
Aug 26th, 2007, 07:07 AM
#2
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:
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.
-
Aug 26th, 2007, 08:06 AM
#3
Thread Starter
Lively Member
Re: Bindingsource .Filter using LIKE and numeric fields
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 !
-
Aug 26th, 2007, 06:25 PM
#4
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.
-
Aug 27th, 2007, 01:21 AM
#5
Thread Starter
Lively Member
Re: Bindingsource .Filter using LIKE and numeric fields
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 !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|