Results 1 to 3 of 3

Thread: Cannot perform 'Like' Operation on System.Datetime and System.String

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Posts
    12

    Cannot perform 'Like' Operation on System.Datetime and System.String

    I am filtering a datagrid by way of textboxes (7 total).
    They all work except for two, the first contains birthdates of which I receive the subject line error "Cannot perform 'Like' Operation on System.Datetime and System.String".

    Here is the code I am using:

    Const MessageBox_Title As String = "Filter"


    ' Fill data before attempting to filter

    Debug.Assert(Not DsStudentInfo1.Tables(tblStudentInfo) Is Nothing, _
    "No product data loaded in dsStudentInfo1.Tables(tblStudentInfo)")

    With DsStudentInfo1.Tables(tblStudentInfo)
    ' Filter view
    .DefaultView.RowFilter = "StudentBirthdate = '" & txtFilterBirthdate.Text & "%'"

    ' Matching data

    If .DefaultView.Count = 0 Then
    MessageBox.Show("No matching rows.", _
    MessageBox_Title, _
    MessageBoxButtons.OK, _
    MessageBoxIcon.Information)
    End If

    ' Bind datagrid to dataView, display matching rows.
    DataGrid1.DataSource = .DefaultView
    End With


    The second is a textbox that Filters a 3integer code and will only allow me to fill one number at a time in the txtfilter box. I type one number, it displays "No matching rows". Put in the 2nd number, same thing, put in the 3rd number and the filter works and displays the matching criteria.

    Here is the code:

    Const MessageBox_Title As String = "Filter"

    ' Fill data before attempting to filter

    Debug.Assert(Not DsStudentInfo1.Tables(tblStudentInfo) Is Nothing, _
    "No product data loaded in dsStudentInfo1.Tables(tblStudentInfo)")

    With DsStudentInfo1.Tables(tblStudentInfo)
    ' Filter view
    .DefaultView.RowFilter = "StudentGradeLevelID = '" & txtFilterGrade.Text & "%'"

    ' Matching data
    If .DefaultView.Count = 0 Then
    MessageBox.Show("No matching rows.", _
    MessageBox_Title, _
    MessageBoxButtons.OK, _
    MessageBoxIcon.Information)
    End If

    ' Bind datagrid to dataView, display matching rows.
    DataGrid1.DataSource = .DefaultView
    End With

    Any help would be greatly appreciated.

    New to VB.net and learning through persistence and the generous help from all of you.

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    As you have seen, you can filter using 'Like' only on strings not on integers / DateTime values.

    You may use < and > and combination of them to filter those values. By the way remember that if you filter on integer values you should not include ' in your filter statment.

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Depending on what your datasource is you could also use BETWEEN(,) for dates.

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