English 中文(简体)
ASP.net LINQ on DataView
原标题:ASP.net LINQ on DataView

一、数据记录

 EnumerableRowCollection<DataRow> query 
    = from order in _table.AsEnumerable()
      where order.Field<Int32>("key") > 2 && order.Field<Int32>("key") < 4
      select order.Field<Int32>("key")=1000, order.Field<string>("name");   

我可以这样说。

审判

select new {key= 1000,name= order.Field<string>("name") };

i got

    Cannot implicitly convert type 
    System.Data.EnumerableRowCollection<AnonymousType#1>    
    to  System.Data.EnumerableRowCollection<System.Data.DataRow> 

如何形成权利问题? 我的任务是用1 000个钥匙取代钥匙,并按现在的名称删除。

问题回答

When you write select new {key= 1000,name= order.Field<string>("name") }, you re creating a new anonymous type that has nothing to do with DataRow.
Therefore, you can t assign it to a EnumerableRowCollection<DataRow>.

为确定汇编错误,修改<代码> EmathableRowCollection<DataRow> to var


However, that won t fix your underlying problem.
LINQ cannot be used to modify data.

您需要使用正常的<代码>foreach loop,并确定key。 价值观,如:

var affectedRows = from order in _table.AsEnumerable()
  where order.Field<Int32>("key") > 2 && order.Field<Int32>("key") < 4
  select row;
foreach(DataRow row in affectedRows) {
    row["key"] = 1000;
}

This code will modify the original DataRows in the original _table.
If you don t want to modify the original _table, you can copy it by calling DataTable.Copy().





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!