Click here to Skip to main content
15,917,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,
Could any body Give an example "How I can Search data inside LINQ query" I want to use it as dataView RowFilter to "Filter" data in datagrid. I'm using this Query

dynamic query;
C#
private void doIt()
{
        query = (from a in myDB.tHE_Move
                 where
                 a.adDateEnd < DateTime.Now
                 select new
                 {
                     Field1= a.Name,
                     Field1 = a.Date,

                 }).ToList();

        dgwGrid.DataSource = query;

}

So if I want to search for specific data, how to use "query" variable, not to select again from DB.
THANKS!
Posted
Updated 4-Dec-11 22:50pm
v2
Comments
[no name] 5-Dec-11 4:51am    
EDIT: added "pre" tag

hi,

you can use,

C#
query.where(s=> s.Field1 == "searchstring").ToList(); 

here in where clause you can add more complex query to filter your data.
you need to add System.Linq namespace in your class.

thanks
-Amit.
 
Share this answer
 
v2
You can further filter
1) by writing one more LINQ on query variable or use Where method to filter
like below.
var result = query.Where(row => row.Field1 == "Ramu");
 
Share this answer
 
You can probably cache the data from the database inside a collection and then use Where clause of LINQ to filter the data.
 
Share this answer
 
You can do this to get what you need:

query.where(s=> s.Field1 == "searchstring").ToList(); 
 
Share this answer
 

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