Results 1 to 5 of 5

Thread: Bindingsource .Filter using LIKE and numeric fields

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Location
    Constanta,Romania
    Posts
    71

    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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Location
    Constanta,Romania
    Posts
    71

    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 !

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Location
    Constanta,Romania
    Posts
    71

    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 !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width