简体   繁体   English

dataRowFilter有什么作用?

[英]What does the dataRowFilter do?

What does the dataRowFilter do? dataRowFilter有什么作用? is it only a condition for the rows? 这仅仅是行的条件吗? because adding a select in the row filter does not work 因为在行过滤器中添加选择不起作用

The code is: 代码是:

Dim strExpr = "ClientID>(select count(*) from Client)-10" (to select the last 10 records);

Dim dv = ds.Tables(0).DefaultView;

dv.RowFilter = strExpr;
Dim newDS = New DataSet();
Dim newDT = dv.ToTable();
newDS.Tables.Add(newDT);

But the code does not work , if I put in strExpr="ClientID>3" the code does work so is the RowFilter only a condition? 但是代码不起作用,如果我将strExpr="ClientID>3"放入代码中,那么RowFilter仅是一个条件吗? because I cant put select in it. 因为我不能在其中放选择。

The DataRowFilter property is used to filter which rows are viewed in the DataView . DataRowFilter属性用于过滤在DataView中查看的行。 The string is internally parsed into DataExpressions . 该字符串在内部解析为DataExpressions You'll find more information about the expression syntax over at MSDN when looking at the Expression property of the DataColumn class. 通过查看DataColumn类的Expression属性,可以在MSDN上找到有关表达式语法的更多信息。 The same syntax applies to the Select function of the DataTable . 相同的语法适用于DataTableSelect函数。

In these LINQ times it's quite trivial to query a data-set/table. 在这些LINQ时代,查询数据集/表非常简单。 For instance, if you have a Client table with indices ranging from 1 to 100 , then the following code will return clients with indices 31 to 40 . 例如,如果您有一个Client表,索引范围为1100 ,则以下代码将返回索引为3140的客户端。

Dim table As DataTable = (
    From row As DataRow
    In ds.Tables("Client")
    Let clientId As Int32 = row.Field(Of Int32)("ClientID")
    Where clientId > 30
    Order By clientId Ascending
    Select row
).Take(10).CopyToDataTable()

PS: The same query can actually be written as a one-liner: PS:相同的查询实际上可以写成一个单行:

Dim table As DataTable = (From row As DataRow In ds.Tables("Client") Let clientId As Int32 = row.Field(Of Int32)("ClientID") Where clientId > 30 Order By clientId Ascending Select row).Take(10).CopyToDataTable()

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

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