G
Guest
Dear All Expert,
I have used the following code to update my mdb file by dataadapter, but it does not work, please help me.
Dim strDBPath As String
Dim con As OleDbConnection
Dim cmd As OleDbCommand
Dim ds As New DataSet
Dim da As OleDbDataAdapter
Dim cmdbuilder As OleDbCommandBuilder
strDBPath = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Demo\DEMO.mdb;Persist Security Info=False"
con = New OleDbConnection(strDBPath)
cmd = New OleDbCommand("select * from Staff where c_emp_no='8452'", con)
con.Open()
da = New OleDbDataAdapter(cmd)
ds.Tables.Add("Staff"
da.Fill(ds, "Staff"
Dim row As DataRow = ds.Tables(0).Rows(0)
row.BeginEdit()
row("c_emp_name") = "Michael"
row.EndEdit()
da = New OleDbDataAdapter(cmd)
cmdbuilder = New OleDbCommandBuilder(da)
da.UpdateCommand = cmdbuilder.GetUpdateCommand
da.UpdateCommand = cmdbuilder.GetDeleteCommand
da.UpdateCommand = cmdbuilder.GetInsertCommand
ds.AcceptChanges()
TextBox1.Text = da.Update(ds, "staff"
Then I check the mdb file, the field ("c_emp_name") does not changed to "Michael
Can anyone point out where should I modify ?
Thank you all
I have used the following code to update my mdb file by dataadapter, but it does not work, please help me.
Dim strDBPath As String
Dim con As OleDbConnection
Dim cmd As OleDbCommand
Dim ds As New DataSet
Dim da As OleDbDataAdapter
Dim cmdbuilder As OleDbCommandBuilder
strDBPath = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Demo\DEMO.mdb;Persist Security Info=False"
con = New OleDbConnection(strDBPath)
cmd = New OleDbCommand("select * from Staff where c_emp_no='8452'", con)
con.Open()
da = New OleDbDataAdapter(cmd)
ds.Tables.Add("Staff"
da.Fill(ds, "Staff"
Dim row As DataRow = ds.Tables(0).Rows(0)
row.BeginEdit()
row("c_emp_name") = "Michael"
row.EndEdit()
da = New OleDbDataAdapter(cmd)
cmdbuilder = New OleDbCommandBuilder(da)
da.UpdateCommand = cmdbuilder.GetUpdateCommand
da.UpdateCommand = cmdbuilder.GetDeleteCommand
da.UpdateCommand = cmdbuilder.GetInsertCommand
ds.AcceptChanges()
TextBox1.Text = da.Update(ds, "staff"
Then I check the mdb file, the field ("c_emp_name") does not changed to "Michael
Can anyone point out where should I modify ?
Thank you all