this code in form load event...
Dim sqlquery As String = "select * from frmStudentReg"
Dim sqlcommand As New OleDbCommand
Dim sqladapter As New OleDbDataAdapter
Dim table As New DataTable
With sqlcommand
.CommandText = sqlquery
.Connection = conn
.ExecuteNonQuery()
End With
With sqladapter
.SelectCommand = sqlcommand
.Fill(table)
End With
For i = 0 To table.Rows.Count - 1
With DataGridView46
.Rows.Add(table.Rows(i)("regno"), table.Rows(i)("name"), table.Rows(i)("class"))
End With
Next
Private Sub ComboBox6_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles ComboBox6.SelectionChangeCommitted
Dim sqlquery As String = "select * from frmStudentReg WHERE class like '%" & ComboBox6.SelectedValue & "%'"
Dim sqlcommand As New OleDbCommand
Dim sqladapter As New OleDbDataAdapter
Dim table As New DataTable
With sqlcommand
.CommandText = sqlquery
.Connection = conn
.ExecuteNonQuery()
End With
With sqladapter
.SelectCommand = sqlcommand
.Fill(table)
End With
For i = 0 To table.Rows.Count - 1
With DataGridView46
.Rows.Add(table.Rows(i)("regno"), table.Rows(i)("name"), table.Rows(i)("class"))
End With
Next
End Sub
datagridview loads the data from table in database. now i want to filter datagridview with the combobox itemselected.
Like if i have data in table like
regno name class
e11 joy one
e22 john two
e33 henry one
then when i select class 'one' in combobox then i want datagridview to be filtered and show only information about class 'one'.. plz help..
sushilsth 0 Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.