Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using an ms-access-2007 database and trying to edit a certain row/column without success.
I can add new rows to the same data base with code without problems. Trying to reduce my original code to a simplest possible test-code and running it shows no error, but does not alter original data.
The data base has a primary key index (ID). I am writing in VS 2019, vb.net.

What I have tried:

with a msgbox I have checked that ds.Tables(0).Rows(0).Item(4) is altered, but next step with the adapter change the data base fail.
I have also tried with adapter.Update(ds.Table(0)) - same result.

Private Sub Button2_Click_(sender As Object, e As EventArgs) Handles Button2.Click
    'testa att uppdatera databas
    cnnTävl = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + TPath + AktTävlNamn + "_" + AktTävlDat + ".mdb")
    Dim strSQL = "Select * FROM Deltagare WHERE Patrull='12' AND Figur='01'"
    Dim cmd As New OleDb.OleDbCommand(strSQL, cnnTävl)
    Dim Adapter As New OleDb.OleDbDataAdapter(cmd)
    Dim ds As New DataSet
    Dim cb As New OleDb.OleDbCommandBuilder(Adapter)
    'Stop
    Try
        cnnTävl.Open()
        Adapter.Fill(ds)
        If ds.Tables(0).Rows.Count = 1 Then
            ds.Tables(0).Rows(0).BeginEdit()
            ds.Tables(0).Rows(0).Item(4) = "Bo Ek"
        Else
            MsgBox("No rows to edit")
            cnnTävl.Close()
            Exit Sub
        End If
        cb.GetUpdateCommand()
        Adapter.Update(ds)
    Catch Er As Exception
        MsgBox("Er= " + Er.Message)
    End Try
    cnnTävl.Close()
End Sub
Posted
Comments
Richard Deeming 25-Oct-21 11:29am    
Try calling EndEdit after you have finished editing the row.
Member 14168791 25-Oct-21 14:08pm    
Thanks Richard!
You made my day! Problem solved!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900