Imports System.Data.OleDb
Public Class edit
Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database\User.mdb;"
Dim cn As New OleDbConnection(strConnection) ' ประกาศตัวแปรสำหรับจัดเก็บ Connection
Dim da As New OleDbDataAdapter
Dim dr As OleDbDataReader
Dim str As String = "SELECT * FROM Vocabulary"
Dim dt As New DataTable
Dim Conn As New OleDbConnection
Dim ds As New DataSet
Dim WithEvents objCurrencyManager As CurrencyManager
Private Sub edit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cbogroup.Items.Add("ไ/ใ")
cbogroup.Items.Add("ซ/ทร")
cbogroup.Items.Add("บัน/บรร")
cbogroup.Items.Add("ตัวการันต์")
cbogroup.Items.Add("การสะกดคำ")
cbogroup.Items.Add("วรรณยุกต์")
cbogroup.Items.Add("ทั่วไป")
da.SelectCommand = New OleDbCommand(str, cn)
Try
da.Fill(ds, "Vocabulary")
Catch ex As OleDbException
MsgBox(ex.Message)
Exit Sub
End Try
txtid.DataBindings.Add("Text", ds.Tables("Vocabulary"), "ID")
txtword1.DataBindings.Add("Text", ds.Tables("Vocabulary"), "Vocabulary1")
txtword2.DataBindings.Add("Text", ds.Tables("Vocabulary"), "Word")
cbogroup.DataBindings.Add("Text", ds.Tables("Vocabulary"), "Group")
ListBox1.Items.Clear()
ListBox1.Items.Add("รหัส" & ControlChars.Tab & "คำศัพท์" & ControlChars.Tab & "คำอ่าน" & ControlChars.Tab & "หมวด")
For Each row As DataRow In ds.Tables("Vocabulary").Rows
ListBox1.Items.Add(row("ID").ToString & ControlChars.Tab & row("Vocabulary1").ToString & ControlChars.Tab & row("Word").ToString & ControlChars.Tab & row("Group").ToString)
Next
objCurrencyManager = Me.BindingContext(ds.Tables("Vocabulary"))
objCurrencyManager_PositionChanged(Nothing, Nothing)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ab As String
ab = txtgroup.Text
cbogroup.Items.Add(ab)
txtgroup.Text = ""
End Sub
Private Sub btned_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btned.Click
Try
Dim cb As OleDbCommandBuilder(da) <---------errorตรงนี้ "Array bounds cannot appear in type"
Dim num As Integer = da.Update(ds, "Vocabulary")
MsgBox("บันทึกแล้ว", MsgBoxStyle.OkOnly)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub objCurrencyManager_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles objCurrencyManager.PositionChanged
End Sub
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
objCurrencyManager.AddNew()
End Sub
Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
objCurrencyManager.RemoveAt(objCurrencyManager.Position)
End Sub
End Class