以dataset作为数据源的vb.net datagridview
我的问题是,有没有一种方法可以过滤数据集中的记录并使用这些记录填充datagridview?例如,一个数据表(有3列:以dataset作为数据源的vb.net datagridview,vb.net,datagridview,dataset,Vb.net,Datagridview,Dataset,我的问题是,有没有一种方法可以过滤数据集中的记录并使用这些记录填充datagridview?例如,一个数据表(有3列:ID,StudentName,Gender)由学生列表填充。我有两个格式的数据网格,即DatagridView1和Datagridview2datagridview 1是Gender等于M的学生列表,而datagridview 2是Gender等于F的学生列表 在我当前的解决方案中,我使用循环 For each iStud as datarow in iDataset.Table
ID
,StudentName
,Gender
)由学生列表填充。我有两个格式的数据网格,即DatagridView1
和Datagridview2
datagridview 1
是Gender
等于M
的学生列表,而datagridview 2
是Gender
等于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
有没有不使用循环的方法?是的,有。您只需使用
选择
过滤数据集即可
例如,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
更新
是的,有。您只需使用
选择
过滤数据集即可
例如,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
更新