Click here to Skip to main content
15,919,178 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want show result Start with A,B,C, and i use this Query,it not work:

var v10 = from a in li.tbl_admin_Brands where a.category.StartsWith("A","B","C") select a;


So plz Provide me solution for this



XML
i also Try This But Again Face an error:

  List<string> lostring = new List<string>();
        lostring.Add("A");
        lostring.Add("B");
        lostring.Add("c");


            var v10 = from a in li.tbl_admin_Brands where lostring.Any(s1 =&gt; a.comp_name.StartsWith(s1)) select a;
            DataList1.DataSource = v10;
            DataList1.DataBind();

Erroir is:

Local sequence cannot be used in LINQ to SQL implementations of query operators except the Contains operator.
Posted
Updated 3-Apr-13 2:03am
v2
Comments
[no name] 3-Apr-13 7:12am    
What exactly does "it not work" mean?
Arun kumar Gauttam 3-Apr-13 7:16am    
if i try this:
var v10 = from a in li.tbl_admin_Brands where a.category.StartsWith("A") select a;
it work fine, And show result which start with "A",

But i want that Result Which Start with any Any of them("A" or "B" or "C") So for this what can i do

There is not String.StartsWith overload which takes multiple string options. You would have to write this as:
C#
var v10 = from a in li.tbl_admin_Brands where a.category.StartsWith("A") ||
                                              a.category.StartsWith("B") ||
                                              a.category.StartsWith("C") select a;
 
Share this answer
 
Comments
_Amy 3-Apr-13 8:02am    
Exactly. +5!
StartsWith is taking only a single pattern. You need to use either an other list or implement a new extension method. You can hind both approaches here: http://stackoverflow.com/questions/4970899/linq-to-sql-query-where-a-string-startswith-an-element-from-a-generic-list[^].
 
Share this answer
 
v3
Comments
Arun kumar Gauttam 3-Apr-13 7:52am    
i also Try This But Again Face an error:

List<string> lostring = new List<string>();
lostring.Add("A");
lostring.Add("B");
lostring.Add("c");


var v10 = from a in li.tbl_admin_Brands where lostring.Any(s1 => a.comp_name.StartsWith(s1)) select a;
DataList1.DataSource = v10;
DataList1.DataBind();

Erroir is:

Local sequence cannot be used in LINQ to SQL implementations of query operators except the Contains operator.
Zoltán Zörgő 3-Apr-13 8:16am    
Makes sense if you sue linq to sql. But you did not mention that. You can use OriginalGriff's answer if you can live with it's limitations.
Hi,

Please refere following.

List lostring = new List();
lostring.Add("A");
lostring.Add("B");

List loArrayString = new List();
loArrayString.Add("Abcd");
loArrayString.Add("MNJ");
loArrayString.Add("PQR");
loArrayString.Add("XYZ");
loArrayString.Add("ASDF");

var result = from c in loArrayString
where lostring.Any(s1 => c.StartsWith(s1))
select c;

GridView1.DataSource = result;
GridView1.DataBind();

This will bind grid view with data start with string array "lostring".
 
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