troubleshooting Question

Pleasse help! Dynamic addtion of AND Where to linq query

Avatar of suran78
suran78 asked on
.NET Programming
12 Comments1 Solution618 ViewsLast Modified:
I am having a hard time solving this problem,  need code for creating a dynamic linq query in C#,  I have 5 dropdown list that searches different column in same database table and return item filtered value to a single listbox.  The problem is there is no sequence that which or all or any wil be selected in DDLs but the combined filtered result should show up in listbox.  I have a working query that is searching and returning result in one column at a time for each DDL selection separately.  Have to add where clauses with AND to add other DDL selections dynamically to this query.  Please help ASAP.  Thx.
Please don't give me sample code, please modify mine to make query dynamic.  Here is that class method that searches for DDL selection in column and return list item to listbox.
public ListItemCollection searchProject(ListItemCollection projList, String searchstr, String columnName)
        DataSet DSToReturn = new DataSet();
        ListItemCollection returnItems = new ListItemCollection();
        DataTable results = (from d in ((DataSet)_MyDataset).Tables["Records"].AsEnumerable()
                             orderby d.Field<string>("Name") ascending
                             where (d.Field<string>(columnName) != null)
                             where d[columnName].ToString().ToLower().Contains(searchstr.ToLower())
                             select d).CopyToDataTable();
        foreach (ListItem li in projList)
            if ((from System.Data.DataRow row in results.Rows
                 where li.Value.Equals(row["value"].ToString(), StringComparison.InvariantCultureIgnoreCase)
                 select row["value"]).Count() > 0)
        return returnItems;

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros