Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I need to make "search button" using linq in ASP.NET, but I can't know how to do that.

I'm using this code, but the result didn't appear: the code is:

C#
if(txtSearch.Text !=null)
{
   string query = string.Format("select * from PROJECTS where {0} like '%{1}%'"
                                                               , sender, e);
    query.ToList();
}
Posted
Comments
Maciej Los 15-Mar-15 5:35am    
The code you provided does not use Linq query. It creates sql query string instead.

Please, read my comment to the question.

I'd suggest to read this: ASP.NET - LINQ[^]
Using LINQ to SQL (Part 1)[^]
Simple Tutorial with example of using LINQ to SQL in ASP.Net Website using C# and VB.Net[^]

Assuming that you want to create queries on the fly, you might be interested in createing dynamic queries. Please, see:
Dynamic LINQ (Part 1: Using the LINQ Dynamic Query Library)[^]
Dynamic LINQ Query in C#[^]
Dynamic Query Sample[^]
 
Share this answer
 
var q = ( from c in db.PRODUCT where c.ProductName == textBox1.Text select c).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