none
Exception Cannot perform 'Like' operation on System.Int32 and System.String. RRS feed

  • Question

  • Hi All,

    Here my code ...........i am getting exception like Cannot perform 'Like' operation on System.Int32 and System.String.

     dtSearch.DefaultView.RowFilter = "ID LIKE '" + txtID.Text + "%'";

    ID is primary key(Int) in my DB. I dont have other option with out like operator...........i have to use like operator.........can any one please help me in this.

    Thanks in advance.
    Nagarjuna Dilip
    Tuesday, December 1, 2009 2:35 PM

Answers

All replies

  • How about "="?

    dtSearch.DefaultView.RowFilter = "ID = " + txtID.Text;


    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light WikiLinkedInForumsBrowser
    Tuesday, December 1, 2009 2:38 PM
    Moderator
  • hi,

    No i cannot use '=' find me using 'like'

    ex:   ID       Name
           1000    John
           1001    Mike
           2000    Johnnnn
           2001    Mikeee


    dtSearch.DefaultView.RowFilter = "Name LIKE 'j%'";

    Output :   ID       Name
                1000    John          
                2000    Johnnnn

    dtSearch.DefaultView.RowFilter = "ID LIKE '1%'";

    Output :   ID       Name
                1000    John          
                1001    Mike
    This is expected out put.........use what ever you want but the out put should be in this format...........


    Nagarjuna Dilip
    Tuesday, December 1, 2009 2:43 PM
  • dtSearch.DefaultView.RowFilter = "Convert(ID, 'System.String') LIKE '" + txtID.Text + "%'";


    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light WikiLinkedInForumsBrowser
    • Marked as answer by NagarjunaDilip Wednesday, December 2, 2009 4:38 AM
    Tuesday, December 1, 2009 2:49 PM
    Moderator
  • How about using BETWEEN rather than LIKE?  If you can't then Dave has the answer for you but it will result in a full table scan.
    Tuesday, December 1, 2009 3:30 PM
  • Hi,

    Thanks David, It helped me..........and mr. jgalley i cannot use 'between' than 'like', david's answer i found as my solution...........any way thanks for you reply...........
    Nagarjuna Dilip
    Wednesday, December 2, 2009 4:40 AM
  • Glad it worked out for you.  Just wondering why you feel (given your data) that these would not be the same result.

    dtSearch.DefaultView.RowFilter = "Convert(ID, 'System.String') LIKE '1%'";
    dtSearch.DefaultView.RowFilter = "Id Between 1000 And 1999";


    Wednesday, December 2, 2009 3:46 PM
  • Hi,

    My problem is i may search by '1%' or '2%' or '3%' and......if i use between i need to provide a bit logic in it...........David solution is more straight forward.........and not only by '1%' i may give '11%' it should able to search between 1100 to 1199 based on user's choice,  display changes...............any way thanks for your reply...............
    Nagarjuna Dilip
    • Marked as answer by NagarjunaDilip Wednesday, January 20, 2010 11:49 AM
    Friday, December 4, 2009 4:29 AM