Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: Frameworkentity
Hi all,
i have 4 columns of different types ,like int,date,string,decimal
i want to search by all these data types and based on the search i will display result to grid view
example of my code which will take the int value ,the problem is its only working when exact value is entered
i want partial text search ,how can i do?

Int32 sid = Convert.ToInt32(id.Text);
        testingModel.testingEntities te = new testingModel.testingEntities();
        if (id.Text != "")
            var disp = from i in te.alltypes
                       where i.@int.Equals(sid)
                       select i;
            GridView1.DataSource = disp;
Posted 24-May-12 4:06am
Edited 24-May-12 4:07am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

hi all,
in where condition use the below code
String sid = id.Text;//textbox name
where SqlFunctions.StringConvert((Decimal)i.columnname).Contains(sid)
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you want to search for a partial numeric match you will need to obviously convert the int to a string and use Contains for the comparison.
I don't have a model setup to test but it should be something like
var disp = from i in te.alltypes
            where i.ToString().Contains(sid)
            select i;
pradeep manne at 24-May-12 10:43am
Hi, Thanks for the reply ur code is working good for strings but when i try for int type its giving the following error: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression. any solution for this error?
Mark Nischalke at 24-May-12 11:55am
Without seeing the model you are using or the fields you are trying to compare I can't answer. However, all .NET object have the ToString method.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
0 Sergey Alexandrovich Kryukov 457
1 sanket saxena 345
2 thatraja 240
3 CPallini 215
4 OriginalGriff 195
0 Sergey Alexandrovich Kryukov 8,809
1 OriginalGriff 5,025
2 Peter Leow 3,839
3 Maciej Los 3,535
4 Abhinav S 3,118

Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 25 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid