Click here to Skip to main content
12,945,066 members (50,414 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
Updated 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 24-May-12 10:43am
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 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
Top Experts
Last 24hrsThis month
OriginalGriff 4,651
CHill60 3,055
Maciej Los 2,423
Jochen Arndt 1,910
ppolymorphe 1,765

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 25 May 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100