结果显示,使用Linq查询从A到F开始 [英] result show,start with A to F using Linq query

查看:108
本文介绍了结果显示,使用Linq查询从A到F开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要显示结果从A,B,C开始,我使用此查询,它不起作用:



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



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.

推荐答案

没有String.StartsWith重载,它接受多个字符串选项。您必须将其写为:

There is not String.StartsWith overload which takes multiple string options. You would have to write this as:
var v10 = from a in li.tbl_admin_Brands where a.category.StartsWith("A") ||
                                              a.category.StartsWith("B") ||
                                              a.category.StartsWith("C") select a;


StartsWith只采用一种模式。您需要使用其他列表或实现新的扩展方法。你可以在这里隐藏这两种方法: http://stackoverflow.com/questions/4970899/linq-to-sql-query-where-a-string-startswith-an-element-from-a-generic-list [ ^ ]。
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[^].


您好,



请关注以下内容。



列表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 =来自loArrayString中的c

其中lostring.Any(s1 => c.StartsWith(s1))

选择c;



GridView1.DataSource =结果;

GridView1。 DataBind();



这将绑定网格视图,数据以字符串数组lostring开头。
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".


这篇关于结果显示,使用Linq查询从A到F开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆