Click here to Skip to main content
12,403,950 members (65,640 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: entity-framework
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;
            GridView1.DataBind();
        }
Posted 24-May-12 4:06am
Updated 24-May-12 4:07am
v2
Rate this: bad
 
good
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)
  Permalink  
v2
Rate this: bad
 
good
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;
  Permalink  
Comments
pradeep manne 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 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


Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 25 May 2012
Copyright © CodeProject, 1999-2016
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