Hello,

 

I would appreciate any help in finding why I get an error when saving back
to a database.

 

I am using vb.net in VS-2019 with sqlite.

 

The error is: "Concurrency violation: the UpdateCommand affected 0 of the
expected 1 records." 

I have worked out that the error only occurs when my table has a date field
which I fill from the underlying database use a sqlitedatadapter as follows:

 

Public connstring As String = "Data
Source=c:\VS-2019\SaveTable\SaveTable\Data\TestDb.db"

Public conn As New SQLiteConnection

 

Public Sub FillMainTables()

    conn.ConnectionString = connstring

    conn.Open()

    DTAllCustomers.Rows.Clear()

    sql = "SELECT * FROM Customers"

    AllCustomersAdapter = New SQLiteDataAdapter(sql, conn)

    AllCustomersAdapter.Fill(DTAllCustomers)

End Sub

 

I then modify a few records in the datatable(DTAllCustomers) using this
code:

 

For i = 0 To DTAllCustomers.Rows.Count - 1
    If DTAllCustomers.Rows(i).Item("sitecode") = "RESI" Then
         DTAllCustomers.Rows(i).Item("Email") = "Changed"
    End If
Next

 

I then try to save the modified table back to the underlying database with:

 

Dim cbAllCustomers As New SQLiteCommandBuilder(AllCustomersAdapter)
AllCustomersAdapter.UpdateCommand = cbAllCustomers.GetUpdateCommand
Try
   AllCustomersAdapter.Update(DTAllCustomers)
Catch ex As Exception
   MsgBox(ex.Message)
End Try

 

When I remove the DATETIME columns in DTAllCustomers the error disappears
and the update completes correctly. Does SQLite change the date
structure/value of the DateTime columns between filling the datatable and
saving back to the datatable?

 

I created the database using "sqlite expert personal".  When I loop through
the DTAllCustomers table I inspect the value of a date field and it appears
as - #2/12/2020 12:00:00 AM# 

 

Any help is greatly appreciated as I have spent weeks trying to solve this
through any number of forums.

 

Brad

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to