如何在datagridview中显示特定记录? [英] How to show specific records in datagridview ?

查看:135
本文介绍了如何在datagridview中显示特定记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库,用于存储用户详细信息。我用一个整数来分隔用户,例如,Admin = 1,Faculty = 2和Student = 3.列的名称是Level。



现在我要显示学院DGV的学生详细信息,学生DGV的学生详细信息。



我该怎么办?



我想使用那些级别编号来反映我的DGV中的数据。



我已经添加了代码,如果我出错了请纠正我。



请考虑我的BAD英语,因为它不是我的母语。



Ty codeproject。



我尝试了什么:



 公开  Sub  fac_dgv()
Dim SDA < span class =code-keyword> As SqlDataAdapter
Dim dbDataSet 作为 DataTable
Dim bSource As BindingSource
尝试
connection.Open()
Dim sql 作为 字符串
sql = SELECT id,dept,sub,name,mob,reg,mod,faculty
command = SqlCommand(sql,connection)
SDA.SelectCommand = command
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
connection.Close()
Me .DataGridView4.DataSource = bSource
SDA.Update(dbDataSet)
Catch ex As 异常
MsgBox(ex.Message)
最后
connection.Dispose ()
结束 尝试
结束 Sub

解决方案

您可以使用 DataView ,请参见此处的示例: C#DataGridView排序和过滤 [ ^ ]



你也可以使用 DataTable.Select ,参见这里的例子:

DataTable.Select Method(String)(System.Data) [ ^ ]


如果要显示主DataGridView中的所有数据和其他DataGridView中的详细信息,您可能想要创建嵌套(或主 - 细节)DataGridView。请参阅:

我如何显示主要细节 [ ^ ]

自定义DataGridView(嵌套DataGridView / TreeGridView) [ ^ ]

主详细数据网格视图 [ ^ ]

I have a Database which stores user details in their. I have separated users with a Integer number like, Admin = 1, Faculty = 2 and Student = 3. Name of the column is Level.

Now I want to show the faculty details in Faculty DGV, Student details in Student DGV.

How can I do that ?

I want to use those Level number to reflect data in my DGV.

I have added the code and please, correct me if Im going wrong.

Please, consider my BAD english as Its not my mother language.

Ty codeproject.

What I have tried:

Public Sub fac_dgv()
        Dim SDA As New SqlDataAdapter
        Dim dbDataSet As New DataTable
        Dim bSource As New BindingSource
        Try
            connection.Open()
            Dim sql As String
            sql = "SELECT id,dept,sub,name,mob,reg,mod,level from faculty"
            command = New SqlCommand(sql, connection)
            SDA.SelectCommand = command
            SDA.Fill(dbDataSet)
            bSource.DataSource = dbDataSet
            connection.Close()
            Me.DataGridView4.DataSource = bSource
            SDA.Update(dbDataSet)
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            connection.Dispose()
        End Try
    End Sub

解决方案

You can use DataView, see example here: C# DataGridView Sorting and Filtering[^]

You can also use DataTable.Select, see example here:
DataTable.Select Method (String) (System.Data)[^]


If you would like to display all data in master DataGridView and details in other DataGridView, you may want to create nested (or master-detail) DataGridView. See:
How do i show master-details[^]
Custom DataGridView (Nested DataGridView / TreeGridView)[^]
Master Detail Datagridview[^]


这篇关于如何在datagridview中显示特定记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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