简体   繁体   English

使用C#4.0中的RowFilter在DataView中过滤编号

[英]Filter number in a DataView using RowFilter in C#4.0

I'm trying to filter my DataView DataSet using RowFilter. 我正在尝试使用RowFilter过滤我的DataView DataSet。

I would like to perform a like statement on an Integer column 我想在Integer列上执行类似的声明

So something like this: 所以像这样:

myDataView.RowFilter ="ID LIKE %1%";

This works fine for string columns but I receive an error when trying this will integers. 这适用于字符串列但我在尝试这个时会收到错误整数。 I receive the follow error: Cannot perform 'Like' operation on System.Int32 and System.Int32. 我收到以下错误:无法在System.Int32和System.Int32上执行'Like'操作。

Anyway of doing a LIKE statement on numbers? 无论如何对数字做一个LIKE语句?

Thanks in advance. 提前致谢。

它与我合作:

"Convert(DataGridColumnName, 'System.String') LIKE '%" & txtBox.Text & "%' "

你必须使用cast转换。

"Convert(ID, 'System.String') LIKE  %1%"

This gets the specific item requested. 这将获得所请求的特定项目。 It works on one item exactly 它完全适用于一个项目

"Convert(DataGridColumnName, 'System.String') LIKE '%" & txtBox.Text & "%' "

Example 1: 例1:

 DV.RowFilter = "Convert( TicketNo , 'System.String') LIKE  '%" + txtTicketNo.Text + "%'

This only receive the exact ticket number if you want to retreive items like that start with it receives all items that start with 这只收到确切的票号如果你想要检索那些以它开头的物品接收所有以物品开头的物品

Example 2: 例2:

DV.RowFilter = "Convert( TicketNo , 'System.String') LIKE  '" + txtTicketNo.Text + "%' ";

In Theory the first Example should be looking in the whole string and searching for matches. 理论上,第一个示例应该查看整个字符串并搜索匹配项。 The one that I have done does not do that maybe I had missed something, 我所做的那件事并没有那样做,也许我错过了什么,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM