我有以下表达式,它接受来自DataRow数组的传递值strValue和Selects;
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'运算符后缺少操作数“
locals窗口中的值是一样的??我在这里缺少什么?
答案 0 :(得分:1)
试试这个
expression = strExpression + " = '" + strValue + "'";
请注意,我在'
之前删除了strExpression
并添加了=
或使用string.Format()
。提高可读性,有助于避免使用代码中的拼写错误
expression = string.Format("{0}='{1}'", strExpression, strValue);