Private Sub member_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox3.Text = Date.Today
TextBox4.Text = DateAdd(DateInterval.Year, 1, Date.Today)
'showDataGrid("Select memId,memPerfix,memFname,memLname,memGender,memIdcard,memNumber,moo,memZone,memDistrict,memPropvince,memPostcode,memTel,memDateRegis,memDateExp from Member")
showDataGrid("Select * from Member")
End Sub
Public Sub connectData() Handles MyBase.Load
Dim s As String
If conn.State = ConnectionState.Open Then conn.Close()
s = "Provider = Microsoft.Jet.OLEDB.4.0;"
s = s + "Data Source = D:\LIBARY1\Library.mdb;"
conn.ConnectionString = s
conn.Open()
End Sub
Public Function ExecuteSQL(ByVal prmSQL As String) As Boolean
connectData()
Dim addCom As New OleDbCommand
With addCom
.CommandType = CommandType.Text
.CommandText = prmSQL
.Connection = conn
.ExecuteNonQuery()
End With
ExecuteSQL = True
End Function
Public Function ExecuteReader(ByVal prmSQL As String) As OleDbDataReader
Dim dr As OleDbDataReader
Dim comm As New OleDbCommand
connectData()
With comm
.CommandType = CommandType.Text
.CommandText = prmSQL
.Connection = conn
dr = .ExecuteReader()
Return dr
End With
End Function
Private Sub showDataGrid(ByVal sql As String)
Dim DS As DataSet
Dim DA As OleDbDataAdapter
DS = New DataSet()
DA = New OleDbDataAdapter(sql, conn)
DA.Fill(DS, "Mem")
'DA.Fill(DT)
Try
DataGridView1.[ReadOnly] = True
If DS.Tables("Mem").Rows.Count > 0 Then
DataGridView1.DataSource = DS.Tables("Mem")
DataGridView1.Columns("memId").HeaderText = "รหัสสมาชิก"
DataGridView1.Columns("memPerfix").HeaderText = "คำนำหน้าชื่อ"
DataGridView1.Columns("memFname").HeaderText = "ชื่อ"
DataGridView1.Columns("memLname").HeaderText = "นามสกุล"
DataGridView1.Columns("memGender").HeaderText = "เพศ"
DataGridView1.Columns("memIdcard").HeaderText = "รหัสบัตรประชาชน"
DataGridView1.Columns("memNumber").HeaderText = "บ้านเลขที่"
DataGridView1.Columns("moo").HeaderText = "หมู่"
DataGridView1.Columns("memZone").HeaderText = "แขวง"
DataGridView1.Columns("memDistrict").HeaderText = "เขต"
DataGridView1.Columns("memPropvince").HeaderText = "จังหวัด"
DataGridView1.Columns("memPostcode").HeaderText = "รหัสไปรษณีย์"
DataGridView1.Columns("memTel").HeaderText = "เบอร์โทร"
DataGridView1.Columns("memDateRegis").HeaderText = "วันที่ออกบัตร"
DataGridView1.Columns("memDateExp").HeaderText = "วันหมดอายุ"
Else
MessageBox.Show("ไม่พบรายการที่ค้นหา", "เตือน", MessageBoxButtons.OK, MessageBoxIcon.[Error])
DataGridView1.DataSource = DS.Tables("Mem")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Imports System.Data.OleDb
Imports System.Data
Imports System.Data.SqlClient
Public Class member
Public conn As New OleDbConnection
Private Sub member_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox3.Text = Date.Today
TextBox4.Text = DateAdd(DateInterval.Year, 1, Date.Today)
'showDataGrid("Select memId,memPerfix,memFname,memLname,memGender,memIdcard,memNumber,moo,memZone,memDistrict,memPropvince,memPostcode,memTel,memDateRegis,memDateExp from Member")
showDataGrid("Select * from Member")
End Sub