Can I achieve a wildcard % in the middle of a DataView RowFilter command?

孤者浪人 提交于 2019-12-24 16:29:45

问题


I have this row filter text: "[Name 1] = '" + forename + "%" + surname + "'" which fails, but if I put the % at the beginning or end it's OK. Is there any way to achieve the same result (i.e. "any" string in the middle of the names)?

Full statement is:

dv = new DataView(MyDataTable, 
"[Name 1] = '" + forename + "%" + surname + "'", 
"", DataViewRowState.CurrentRows); 

回答1:


Just a free thougth, try:

dv = new DataView(MyDataTable, 
"[Name 1] = '" + forename + "%' AND [Name 1] = '%" + surname + "'", 
"", DataViewRowState.CurrentRows); 

EDIT: some documentation:

"A wildcard is allowed at the start and end of a pattern, or at the end of a pattern, or at the start of a pattern. [...] Wildcard characters are not allowed in the middle of a string. For example, 'te*xt' is not allowed."

My guess would be it's for performance reasons (?)



来源:https://stackoverflow.com/questions/13289735/can-i-achieve-a-wildcard-in-the-middle-of-a-dataview-rowfilter-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!