Imports System.Data
Imports System.Data.OleDb
Public Class _11F
    Dim dr As OleDbDataReader
    Dim cmd As New OleDbCommand
    Dim gSQL As String
    Private Sub _11F_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Call connectdatabase()
        Call SetGrid()
        Call Showdata()
    End Sub
    Private Sub SetGrid()
        If dgvem.RowCount > 0 Then
            dgvem.Columns(0).HeaderText = ""
            dgvem.Columns(1).HeaderText = ""
            dgvem.Columns(1).Width = 150
            dgvem.Columns(2).HeaderText = ""
            dgvem.Columns(3).HeaderText = ""
            dgvem.Columns(3).Width = 120
            dgvem.Columns(4).HeaderText = ""
            dgvem.Columns(5).HeaderText = ""
            dgvem.Columns(6).HeaderText = ""
            dgvem.Columns(7).HeaderText = ""

        End If
    End Sub
    Private Sub Showdata()
        Dim dt As New DataTable
        gSQL = "Select Food_ID,Food_name,TypeF_ID,TypeR_ID,Food_price,Food_country,Food_amper,Food_address,Food_tel,Food_email,Food_contact,Food_CTstatus  
From Foods_Train"
        With cmd
            .CommandType = CommandType.Text
            .CommandText = gSQL
            .Connection = cnn
            dr = .ExecuteReader
            If dr.HasRows Then
                dt.Load(dr)
                dgvem.DataSource = dt
                SetGrid()
            End If
            dr.Close()
        End With
    End Sub
    Private Sub txtSearch_TextChanged(sender As Object, e As EventArgs) Handles txtSearch.TextChanged
        Dim dt As New DataTable
        gSQL = "Select Food_ID,Food_name,TypeF_ID,TypeR_ID,Food_price,Food_country,Food_amper,Food_address,Food_tel,Food_email,Food_contact,Food_CTstatus  
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)
                dgvem.DataSource = dt
                SetGrid()
            End If
            dr.Close()
        End With
    End Sub
    Private Sub dgvem_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgvem.CellMouseDoubleClick
        If e.RowIndex >= 0 Then
            addem.TextBox8.Text = dgvem.Rows(e.RowIndex).Cells(1).Value
            addem.TextBox3.Text = dgvem.Rows(e.RowIndex).Cells(4).Value
            Me.Close()
        End If
    End Sub
End Class