Imports System.Data
Imports System.Data.OleDb
Public Class _11P
    Dim dr As OleDbDataReader
    Dim cmd As New OleDbCommand
    Dim gSQL As String
    Private Sub _11P_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 = "เบอร์โทรศัพท์"
            dgvem.Columns(8).HeaderText = "ที่อยู่สถานที่"
            dgvem.Columns(9).HeaderText = "ชื่อผู้ติดต่อ"
            dgvem.Columns(10).HeaderText = "ตำแหน่งผู้ติดต่อ"

        End If
    End Sub
    Private Sub Showdata()
        Dim dt As New DataTable
        gSQL = "Select Place_ID,Place_name,Place_price,Place__qtyP,Place__qtyN,Place_country,Place_email,Place_tel,Place_address,
Place_contact,Place_CTstatus From Place_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 Place_ID,Place_name,Place_price,Place__qtyP,Place__qtyN,Place_country,Place_email,Place_tel,Place_address,
Place_contact,Place_CTstatus From Place_Train  Where Place_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.TextBox7.Text = dgvem.Rows(e.RowIndex).Cells(1).Value
            addem.TextBox2.Text = dgvem.Rows(e.RowIndex).Cells(2).Value
            Me.Close()
        End If
    End Sub
End Class