如何正确筛选数据表(datatable.select) [英] How to correctly filter a datatable (datatable.select)

查看:307
本文介绍了如何正确筛选数据表(datatable.select)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim dt As New DataTable
Dim da As New SqlDataAdapter(s, c)

        c.Open()
        If Not IsNothing(da) Then
            da.Fill(dt)
            dt.Select("GroupingID = 0")
        End If

        GridView1.DataSource = dt
        GridView1.DataBind()
        c.Close()

当我打电话da.fill我从我的查询中插入的所有记录。然后,我希望能过滤它们当我运行上面的code,只显示那些在GroupingID等于0。我对所有的数据psented $ P $,过滤器没有工作。请你能告诉我如何得到这个工作正常。谢谢你。

When I call da.fill I am inserting all records from my query. I was then hoping to filter them to display only those where the GroupingID is equal to 0. When I run the above code. I am presented with all the data, the filter did not work. Please can you tell me how to get this working correctly. Thanks.

推荐答案

dt.Select()返回数据行的数组。

你为什么不使用数据视图?

Why don't you use a DataView?

 DataView dv = new DataView(dt);
 dv.RowFilter = "GroupingID = 0";
 GridView1.DataSource = dv;

这篇关于如何正确筛选数据表(datatable.select)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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