将sqlquery转换为rowfilter数据集 [英] Convert sqlquery to rowfilter dataset

查看:135
本文介绍了将sqlquery转换为rowfilter数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将sql查询转换为行过滤器DataTable c#



 strSql =SELECT TOP+ this.mintPageSize + 
* FROM tblEmp WHERE E_Id NOT IN+
(SELECT TOP+ intSkip +E_Id FROM tblEmp);





我的尝试:



 strSql =SELECT TOP+ this.mintPageSize + 
* WHERE#NOT IN+
(SELECT TOP+ intSkip +#) ;

DataView dv = new DataView(documentDataTable);
//创建查询
dv.RowFilter = strSql;

解决方案

作为 MSDN文档 [ ^ ]说:

MSDN写道:

要形成RowFilter值,请指定列的名称,后跟运算符和要过滤的值。该值必须使用引号。例如:

LastName ='Smith'



所以, RowFilter 无法按预期方式过滤数据。有关可以使用的表达式的更多信息,请访问: DataColumn.Expression属性(System.Data) [ ^ ]



为了能够实现这一点,你可以使用Linq To DataSet [ ^ ]。

有关详细信息,请参阅:

LINQ to DataSet示例 [ ^ ]

101 LINQ样本中C# [ ^ ]

LINQ to DataSet中的查询 [ ^ ]

查询数据集(LINQ to DataSet) [ ^


i want to convert the sql query to Row filter DataTable c#

strSql = "SELECT TOP " + this.mintPageSize +
      " * FROM tblEmp WHERE E_Id NOT IN " +
      "(SELECT TOP " + intSkip + " E_Id FROM tblEmp)";



What I have tried:

strSql = "SELECT TOP " + this.mintPageSize +
    " * WHERE # NOT IN " +
    "(SELECT TOP " + intSkip + " #)";

DataView dv = new DataView(documentDataTable);
//creating query
dv.RowFilter = strSql;

解决方案

As MSDN documentation[^] says:

MSDN wrote:

To form a RowFilter value, specify the name of a column followed by an operator and a value to filter on. The value must be in quotation marks. For example:
"LastName = 'Smith'"


So, RowFilter cannot filter data the way you expect. More about expressions avalible to use you can find here: DataColumn.Expression Property (System.Data)[^]

To be able to achieve that, you can use Linq To DataSet[^].
For further details, please see:
LINQ to DataSet Examples[^]
101 LINQ Samples in C#[^]
Queries in LINQ to DataSet[^]
Querying DataSets (LINQ to DataSet)[^]


这篇关于将sqlquery转换为rowfilter数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆