DataView中的RowFilter属性怎么用?有什么作用啊?在线等!解决就送分!!

解决方案 »

  1.   

    根SQL的用法一样,RowFilter = "字段名=‘变量或常量’"
      

  2.   

    筛选功能
    如:MyTable.DefaultView.RowFilter = "city = 上海" ,如果绑定到表格,你就会看到只显示城市为上海的记录
      

  3.   

    过滤DataView所匹配行的记录。
    就像sql语句的where 子句,这样比喻不知恰当否?
      

  4.   

    你可以看下msdn,上面解释的很清楚啦
    [Visual Basic] 
    Private Sub MakeDataView()
       Dim dv As DataView
       dv = New DataView
       With dv
          .Table = DataSet1.Tables("Suppliers")
          .AllowDelete = True
          .AllowEdit = True
          .AllowNew = True
          .RowFilter = "City = 'Berlin'"
          .RowStateFilter = DataViewRowState.ModifiedCurrent
          .Sort = "CompanyName DESC"
       End With
       
       ' Simple bind to a TextBox control
       Text1.DataBindings.Add("Text", dv, "CompanyName")
    End Sub[C#] 
    private void MakeDataView() 
    {
       DataView dv = new DataView();   dv.Table = DataSet1.Tables["Suppliers"];
       dv.AllowDelete = true;
       dv.AllowEdit = true;
       dv.AllowNew = true;
       dv.RowFilter = "City = 'Berlin'";
       dv.RowStateFilter = DataViewRowState.ModifiedCurrent;
       dv.Sort = "CompanyName DESC";
       
       // Simple bind to a TextBox control
       Text1.DataBindings.Add("Text", dv, "CompanyName");
    }
      

  5.   

    RowFilter相当于再次过滤,也就是在你查询的结果中DataView再作一次你指定的条件作并查询,一般和SQL中的where条件写法类似,但有不同,说见MSDN “RowFilter”、“DataColumn.Expression” 属性