在linq中使用带参数的select [英] Using select in linq with parameter
问题描述
有人可以告诉我,如果此行有问题则会出现此错误
语法错误:' 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 thattable
is aSystem.Data.DataTable
This is not LINQ (as you state in the tags) what you show here. LINQ would return anIEnumerable<T>
and theSelect
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. aWhere
call)?
Regards
Andi
这篇关于在linq中使用带参数的select的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!