
Imports System.Data
Imports System.Data.OleDb
Public Class _11N
    Dim dr As OleDbDataReader
    Dim cmd As New OleDbCommand
    Dim gSQL As String
    Private Sub _11N_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(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 Nar_ID,Nar_name,Nar_genius,Nar_Status,Nar_price,Nar_address,Nar_tel,Nar_email 
From Narretor_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 Nar_ID,Nar_name,Nar_genius,Nar_Status,Nar_price,Nar_address,Nar_tel,Nar_email 
From Narretor_Train Where Nar_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.TextBox9.Text = dgvem.Rows(e.RowIndex).Cells(1).Value
            addem.TextBox1.Text = dgvem.Rows(e.RowIndex).Cells(4).Value
            Me.Close()
        End If
    End Sub
End Class