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.. 

From what i understand, you want to populate the particular class students by selecting the combobox?

if thats your question, the answer is you have to change the query to the following.

Dim sqlquery As String = "select * from frmStudentReg WHERE class like '%" & >ComboBox6.SelectedValue & "%'"

you have to change it as

Dim sqlquery As String = "select * from frmStudentReg WHERE class='"&ComboBox6.SelectedValue"'

Hope this helps you my friend.

This article has been dead for over six months. Start a new discussion instead.