Imports System.Data
Imports MySql.Data.MySqlClient
Public Class frmCheck
Private Sub frmCheck_Load() Handles MyBase.Load
con = New MySqlConnection
If con.State = ConnectionState.Closed Then
con.Open()
End If
For i = 1 To 12
ComboMonth.Items.Add(MonthName(i))
Next
ComboMonth.SelectedIndex =_
ComboMonth.FindStringExact(Monthame(DateTime.Now.Month))
Dim y As Integer = DateTime.Now.Year
ComboYear.Items.Add(y + 543)
ComboYear.Items.Add((y - 1) + 543)
End Sub
Public Sub loadfile()
Dim sqlQuery As String
sqlQuery = "select ProductID as รหัสสินค้า,Month as เดือน ,Year as ปี,SalePrice as ราคาขาย from Chack"
Dim sqlAdapter As New MySqlDataAdapter
Dim sqlCmd As New MySqlCommand
Dim sqlTable As New DataTable
'Dim i As Integer
With sqlCmd
.CommandText = sqlQuery
.Connection = con
End With
With sqlAdapter
.SelectCommand = sqlCmd
.Fill(sqlTable)
End With
DataGridView1.DataSource = sqlTable
End Sub
Private Sub DataGridView1_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim i As Integer
i = DataGridView1.CurrentRow.Index
ComboMonth.Text = DataGridView1.Item(0, i).Value
ComboYear.Text = DataGridView1.Item(1, i).Value
End Sub
End Class