Imports System.Data
Imports System.Data.OleDb
Public Class Form3
    Dim dr As OleDbDataReader
    Dim cmd As New OleDbCommand
    Dim gSQL As String
    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Call connectdatabase()

        ListView1.Columns.Add("รหัสพนักงาน", 100, HorizontalAlignment.Center)
        ListView1.Columns.Add("ชื่อพนักงาน", 200, HorizontalAlignment.Center)
        ListView1.Columns.Add("แผนก", 100, HorizontalAlignment.Center)
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Form2.ShowDialog()
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        If eno.Text = "" Or ename.Text = "" Then
            Exit Sub
        End If
        ListView1.Items.Add(eno.Text)
        ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(ename.Text)
        ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(epanak.Text)

        eno.Text = ""
        ename.Text = ""
        epanak.Text = ""
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        For i = 1 To ListView1.Items.Count - 1
            gSQL = "Insert into Train22 values("
            gSQL += "'" & no.Text & "',"
            gSQL += "'" & ListView1.Items(i).Text & "',"
            gSQL += "'" & ListView1.Items(i).SubItems(1).Text & "',"

            gSQL += "'" & ListView1.Items(i).SubItems(2).Text & "')"

            With cmd
                .CommandType = CommandType.Text
                .CommandText = gSQL
                .Connection = cnn
                .ExecuteNonQuery()
            End With
        Next
        MessageBox.Show("เพิ่มรายการใหม่แล้ว", "เพิ่มขอ้มูล", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub
    'Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    '    For i = 0 To ListView1.Items.Count - 1
    '        gSQL = "Insert into Train22 values("
    '        gSQL += "'" & i + 1 & "',"
    '        gSQL += "'" & ListView1.Items(i).Text & "',"
    '        gSQL += "'" & ListView1.Items(i).SubItems(1).Text & "',"
    '        gSQL += "'" & ListView1.Items(i).SubItems(2).Text & "')"

    '        With cmd
    '            .CommandType = CommandType.Text
    '            .CommandText = gSQL
    '            .Connection = cnn
    '            .ExecuteNonQuery()
    '        End With
    '    Next
    '    MessageBox.Show("เพิ่มรายการใหม่แล้ว", "เพิ่มขอ้มูล", MessageBoxButtons.OK, MessageBoxIcon.Information)
    'End Sub
End Class