【问题标题】:vb.net datagridview with dataset as datasource以数据集为数据源的 vb.net datagridview
【发布时间】:2012-02-09 10:03:28
【问题描述】:

我的问题是,有没有办法过滤数据集中的记录并使用该记录来填充 datagridview?例如,一个数据表(有 3 列:IDStudentNameGender)填充了学生列表。我的表格中有两个数据网格,即DatagridView1Datagridview2DatagridView1Gender 等于M 的学生列表,DatagridView2Gender 等于F 的学生列表。

在我当前的解决方案中,我使用的是循环。

For each iStud as datarow in iDataset.Tables(0).Rows
      IF iStud.Item("Gender").ToString = "M" Then
            'add this record to DatagridView1
      Else
            'add this record to DatagridView2
      End If
Next

有没有不使用循环的方法?

【问题讨论】:

    标签: vb.net datagridview dataset


    【解决方案1】:

    是的,有。您需要做的就是使用SELECT 过滤数据集。

    例如,

    DatagridView1.Datasource = xSet.Tables("StudentList").SELECT("Gender = 'M'")
    DatagridView2.Datasource = xSet.Tables("StudentList").SELECT("Gender = 'F'")
    

    简要说明:

    xSet          is the name of the Dataset
    StudentList   is the name of the Datatable
    Gender        is the name of the Column where you want to filter
    

    更新

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-22
      • 1970-01-01
      • 2017-02-07
      • 1970-01-01
      • 1970-01-01
      • 2013-03-07
      • 2012-04-25
      • 2018-01-15
      相关资源
      最近更新 更多