Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
4.00/5 (1 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?


C#
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
Updated 24-May-12 4:07am
v2

hi all,

in where condition use the below code

String sid = id.Text;//textbox name

where SqlFunctions.StringConvert((Decimal)i.columnname).Contains(sid)
 
Share this answer
 
v2
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

SQL
var disp = from i in te.alltypes
            where i.ToString().Contains(sid)
            select i;
 
Share this answer
 
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?
[no name] 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900