从DataTable获取数据时出错';s选择方法使用“;喜欢“;操作人员
本文关键字:方法 喜欢 操作 选择 数据 获取 DataTable 出错 | 更新日期: 2023-09-27 18:19:31
我使用以下代码
foreach (KeyValuePair<string, string> kvp in letGrdSignList)
{
//Check if added function in definition is modified, if yes then don't add it in signature list
DataRow[] dLetRow = dtLet.Select("Definition" + "Like"" + "'" +
"%"+ kvp.Value + "%" + "'");
//kvp.value contains "local:try2values($arg1 as xs:decimal,$arg2 as xs:float*)"
//Above line results in error
if (dLetRow.Length > 0)
{
//Check if signature already exists
if (!strList.ContainsKey(kvp.Key))
strList.Add(kvp.Key, kvp.Value);
}
//else
// //Remove from list if signature is not present in any defination column
// letGrdSignList.Remove(sLetSignature);ss
}
I am getting following error
{System.Data.EvaluateException: Error in Like operator: the string pattern '%local:try2values($arg1 as xs:decimal,$arg2 as xs:float*)%' is invalid.
at System.Data.LikeNode.AnalyzePattern(String pat)
at System.Data.LikeNode.Eval(DataRow row, DataRowVersion version)
at System.Data.Select.AcceptRecord(Int32 record)
at System.Data.Select.GetLinearFilteredRows(Range range)
at System.Data.Select.SelectRows()
at System.Data.DataTable.Select(String filterExpression)
at WPFApp.QueryGenerator.GetSignatureList()
代码的屏幕截图
如果找到此通配符
在LIKE比较中,*和%可以互换用于通配符。如果LIKE子句中的字符串包含*或%,则这些字符应括在方括号([])中。如果子句中有括号,则每个括号字符都应括在括号中(例如[[]或[]])。通配符允许出现在模式的开始和结束处,或者出现在模式结束处,或出现在模式开始处。例如:
"ItemName LIKE'产品'"
"ItemName LIKE'*product'"
"ItemName LIKE'product*'"
字符串中间不允许使用通配符。例如,不允许使用"te*xt"。
使用Like运算符时需要转义"%"
//Check if added function in definition is modified, if yes then don't add it in signature list
DataRow[] dLetRow = dtLet.
Select("Definition Like '[%]%" + kvp.Value + "[%]%'");
我用这个替换了行
DataRow[] dLetRow = dtLet.Select("Definition" + "Like"" + "'" +
"%"+ kvp.Value.replace("*","[*]") + "%" + "'");
这修复了错误,但我不确定这种方法是否正确