在linq中使用带参数的select [英] Using select in linq with parameter

查看:63
本文介绍了在linq中使用带参数的select的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我,如果此行有问题则会出现此错误

语法错误:'  name'  operator    



DataRow [] rows = table.Select(columnY +='+ columnYValue + ');



该表包含假定的行。

解决方案

<的值是否为

 columnY +   =' + columnYValue +  ' 

是否包含有效过滤器?



列名称中的空格应该可以通过将列名括在方括号中来固定[]

  string  .Format(  [{0}] ='{1}',columnY,columnYValue)

请参阅:https://msdn.microsoft.com/en-us/library/system.data .datacolumn.expression(v = vs.100).aspx [ ^ ]





这假设 System.Data.DataTable


< blockquote>这不是LINQ(正如你在标签中所述)你在这里展示的内容。 LINQ将返回 IEnumerable< T> Select 方法需要一个委托,通常以lambda表达式的形式给出。 br />
你想要选择什么?表的所​​有元素?你想申请任何过滤器(例如哪里致电)?

问候

Andi


Can somebody please tell me if something is wrong with this line it gives this error

Syntax error: Missing operand after 'name' operator."


DataRow[] rows = table.Select(columnY +"='"+ columnYValue +"'");

The table contains the supposed rows.

解决方案

Does the value of

columnY +"='"+ columnYValue +"'"

contain a valid filter?

The space in the column name should be fixable by enclosing the column name in square brackets []

string.Format("[{0}]='{1}'", columnY, columnYValue)

See: https://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression(v=vs.100).aspx[^]

[Edit: MTH]
This is assuming that table is a System.Data.DataTable


This is not LINQ (as you state in the tags) what you show here. LINQ would return an IEnumerable<T> and the Select method requires a delegate, usually given as a lambda expression.
What exactly do you want to select? All elements of a table? Do you want to apply any filter (e.g. a Where call)?
Regards
Andi


这篇关于在linq中使用带参数的select的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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