Imports System.Data.OleDb
Imports System.Data
Public Class Form1
Dim con As New OleDbConnection
Private Sub SetDisplay(chk As Boolean)
Label1.Enabled = chk
TextBox1.Enabled = chk
Label2.Enabled = Not chk
TextBox2.Enabled = Not chk
End Sub
Public Sub DisplayDatagrid(sql As String, dgv As DataGridView)
con.Open()
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter
da = New OleDbDataAdapter(sql, con)
da.Fill(dt)
dgv.DataSource = dt.DefaultView
con.Close()
End Sub
Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.CheckedChanged
SetDisplay(True)
End Sub
Private Sub RadioButton5_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton5.CheckedChanged
SetDisplay(False)
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
DisplayDatagrid("SELECT * FROM tb_Products", DataGridView1)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\admim\Documents\ฐานข้อมูล31.accdb"
Label1.Enabled = True
TextBox1.Enabled = True
Label2.Enabled = True
TextBox2.Enabled = True
End Sub
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
DisplayDatagrid("SELECT * FROM tb_DD", DataGridView1)
End Sub
End Class