Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在表达式中使用传递的值_C#_Winforms_.net 3.5 - Fatal编程技术网

C# 如何在表达式中使用传递的值

C# 如何在表达式中使用传递的值,c#,winforms,.net-3.5,C#,Winforms,.net 3.5,我有下面的表达式,它接受传递的值strValue并从DataRow数组中选择 expression = "InvoiceDate='" + strValue + "'"; //value in Locals window = "InvoiceDate='05/28/2013'" 我尝试将列名作为值传递给它 expression = "'" + strExpression + "'" + strValue + "'"; //value in Locals window = "InvoiceDat

我有下面的表达式,它接受传递的值strValue并从DataRow数组中选择

expression = "InvoiceDate='" + strValue + "'"; //value in Locals window = "InvoiceDate='05/28/2013'"
我尝试将列名作为值传递给它

expression = "'" + strExpression + "'" + strValue + "'"; //value in Locals window = "InvoiceDate='05/28/2013'"

DataRow[] returnedRows; 
returnedRows = theDataConn.DataSet.Tables["Invoices"].Select(expression); //Error
返回“语法错误:“05”运算符后缺少操作数”

“局部变量”窗口中的值相同??此处缺少什么?

尝试使用此选项

expression = strExpression + " = '" + strValue + "'";
请注意,我在
strExpression
之前删除了
,并添加了
=

或者使用
string.Format()

expression = string.Format("{0}='{1}'", strExpression, strValue);

另外,@KFP应该注意,除了非常简单的情况(两个字符串串联)之外,字符串串联从来都不是一个好主意。