Imports System.Data
Imports System.Data.OleDb
Public Class _1
    Dim dr As OleDbDataReader
    Dim cmd As New OleDbCommand
    Dim gSQL As String

    Private Sub _1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Call connectdatabase()

    End Sub

    Private Sub txtSearch_TextChanged(sender As Object, e As EventArgs)
        Dim dt As New DataTable
        gSQL = "select * from Foods_Train where Food_name Like '%" & txtSearch.Text & "%'"
        With cmd
            .CommandType = CommandType.Text
            .CommandText = gSQL
            .Connection = cnn
            dr = .ExecuteReader
            If dr.HasRows Then
                dt.Load(dr)
                dgvProducts.DataSource = dt
            End If
            dr.Close()
        End With
    End Sub

    Private Sub dgvProducts_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgvProducts.CellMouseDoubleClick
        If e.RowIndex >= 0 Then

            Food.foodNo.Text = dgvProducts.Rows(e.RowIndex).Cells(0).Value
            Food.foodname.Text = dgvProducts.Rows(e.RowIndex).Cells(1).Value
            Food.cboTR.SelectedValue = dgvProducts.Rows(e.RowIndex).Cells(2).Value
            Food.cboTF.SelectedValue = dgvProducts.Rows(e.RowIndex).Cells(3).Value
            Food.foodprice.Text = dgvProducts.Rows(e.RowIndex).Cells(4).Value
            Food.foodCT.Text = dgvProducts.Rows(e.RowIndex).Cells(5).Value
            Food.foodamper.Text = dgvProducts.Rows(e.RowIndex).Cells(6).Value
            Food.foodad.Text = dgvProducts.Rows(e.RowIndex).Cells(7).Value
            Food.foodtel.Text = dgvProducts.Rows(e.RowIndex).Cells(8).Value
            Food.foodemail.Text = dgvProducts.Rows(e.RowIndex).Cells(9).Value
            Food.foodcont.Text = dgvProducts.Rows(e.RowIndex).Cells(10).Value
            Food.foodcontt.Text = dgvProducts.Rows(e.RowIndex).Cells(11).Value
            Me.Close()
        End If
    End Sub
End Class