Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
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
Posted
Updated 13-Mar-18 7:49am
v2
Comments
ZurdoDev 13-Mar-18 8:07am    
sql = "SELECT id,dept,sub,name,mob,reg,mod,level from faculty WHERE level = 2"

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)[^]
 
Share this answer
 
v2
Comments
Maciej Los 13-Mar-18 10:18am    
Rick, seems OP is asking about nested DataGridView.
RickZeeland 13-Mar-18 10:25am    
Could not make that up from the question, did you have contact with the OP ?
Maciej Los 13-Mar-18 10:47am    
Yeah, virtual minds connection. ;)
:laugh:
Babai JermenKeller Sasmal 13-Mar-18 10:49am    
Ty its working as Universe.
Maciej Los 13-Mar-18 12:31pm    
Great, give Him a 5! (use stars on right-top corner of solution)
I did it already.
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900