Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.OleDb
Public Class Booktype
Dim StrConn As String
Dim Conn As New OleDbConnection()
Dim da As OleDbDataAdapter()
Dim ds As New DataSet()
Private Sub Booktype_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'เชื่อมต่อฐานข้อมูล
StrConn = "Provider=Microsoft.JET.OLEDB.4.0;data source=C:\Users\Public\Documents\BookRent.accdb"
With Conn 'เริ่มต้นเชื่อมต่อฐานข้อมูล
If .State = ConnectionState.Open Then .Close()
.ConnectionString = StrConn
.Open()
End With
Dim Com As New OleDbCommand
With Com
.CommandText = "[BookType Qry]"
.CommandType = CommandType.StoredProcedure
.Connection = Conn
End With
da = New OleDbDataAdapter(Com)
da.Fill(ds, "BookType")
If ds.Tables("Booktype").Rows.Count <> 0 Then
With dgvBookType
.ReadOnly = True
.DataSource = ds.Tables("BookType")
End With
End If
End Sub
End Class