Imports System.Data.OleDb
Imports system.Data
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 ' ประกาศตัวแปรสำหรับจัดเก็บ DataAdapter
Dim ds As New DataSet ' ประกาศตัวแปรสำหรับจัดเก็บ DataSet
Dim cm As New OleDbCommand(str, cn)
Dim dr As OleDbDataReader
Dim str As String = "SELECT * FROM Vocabulary"
Dim WithEvents objCurrencyManager As CurrencyManager
Private Sub Edit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
da.SelectCommand = New OleDbCommand(str, cn)
Try
da.Fill(ds, "Vocabulary")
Catch ex As OleDbException
MsgBox(ex.Message)
Exit Sub
End Try
dgvword.DataSource = ds.Tables("Vocabulary")
txtid.DataBindings.Add("Text", ds.Tables("Vocabulary"), "ID")
txtvocab.DataBindings.Add("Text", ds.Tables("Vocabulary"), "Vocabulary1")
txtword.DataBindings.Add("Text", ds.Tables("Vocabulary"), "Word")
txtlevel.DataBindings.Add("Text", ds.Tables("Vocabulary"), "level")
objCurrencyManager = Me.BindingContext(ds.Tables("Vocabulary"))
objCurrencyManager_PositionChanged(Nothing, Nothing)
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)
objCurrencyManager_PositionChanged(Nothing, Nothing)
End Sub
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
Try
Dim ac As New OleDbCommandBuilder(da)
objCurrencyManager.EndCurrentEdit()
Dim save As Integer = da.Update(ds, "Vocabulary") <-------error บันทัดนี้
MsgBox("บันทึกแล้ว", MsgBoxStyle.OkOnly)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
ถ้าแก้ไขข้อมูลลงไปมันจะerrorว่า Syntax error in UPDATE statement.
ช่วยหน่อยนะ........