Imports System.Data.OleDb
Imports System.Data
Public Class Form3
Dim cmd As OleDbConnection
Dim Ds As DataSet
Dim Da As OleDbDataAdapter
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
cmd = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\CRU_003\Documents\Visual Studio 2008\Projects\MyProject\ข้อมูลนักศึกษา.accdb")
cmd.Open()
MsgBox("Connection")
Call DataShow()
Catch ex As Exception
MsgBox("No connection")
End Try
'If cmd.State = ConnectionState.Open Then
' Else
'End If
End Sub
Sub DataShow()
Ds = New DataSet
Da = New OleDbDataAdapter("SELECT * FROM Student", cmd)
Da.Fill(Ds, "Student")
DataGridView1.DataSource = Ds.Tables("Student")
End Sub
Private Sub ButAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButAdd.Click
Ds = New DataSet
Da = New OleDbDataAdapter("INSERT INTO Student (ลำดับ,รหัสแท็ก,ชื่อ,รหัสนักศึกษา,คณะ/สำนัก,สาขาวิชา) VALUES ('" & TextID.Text.Trim.ToUpper & "','" & TextTAGID.Text.Trim.ToUpper & "','" & TextNane.Text.Trim.ToUpper & "','" & TextSTDID.Text.Trim.ToUpper & "','" & Textคณะ.Text.Trim.ToUpper & "','" & Textวิชา.Text.Trim.ToUpper & "')", cmd)
Da.Fill(Ds, "Student")
Call DataShow()
TextID.Clear()
TextTAGID.Clear()
TextNane.Clear()
TextSTDID.Clear()
Textคณะ.Clear()
Textวิชา.Clear()
End Sub
End Class