Click here to Skip to main content
14,330,776 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello

I am getting a concurrency violation on my updatecommand when I try to save a datatable back to the database. I am changing one column in about 90% of my rows in a 4200 plus row datatable. I am using a datatable that has a primarykey. I am also using a sqlitedatadapter.


I Your help would be appreciated
Brad

What I have tried:

fill the datatable with this:

<pre>sql = "SELECT * FROM Customers WHERE Status = 'Active'"
    ActiveCustomersAdapter = New SQLiteDataAdapter(sql, conn)
    ActiveCustomersAdapter.Fill(DTActiveCustomers)


I fill the table, loop through the table changing one date field by adding an increment variable to a date column and then try to save back to the database with:

Dim cbActiveCustomers As New SQLiteCommandBuilder(ActiveCustomersAdapter)
  conn.Open()                 ... forgot to show this
  ActiveCustomersAdapter.Update(DTActiveCustomers)
  conn.Close()                ... and this       thanks MadMyche



There are no concurrent users and no other activity on the database. I am obviously not doing something correctly but have not found what I am missing.
I have searched concurrency issues but most explain issues that do not specifically relate. I have stripped the project back to doing nothing but:
1. open the database and fill the datatable
2. modify the field in about 90% of the tables rows
3. save the table back to the database
Posted
Updated 4-Oct-19 17:11pm
v2
Comments
MadMyche 28-Sep-19 8:32am
   
Where is connection.Open()</code) and <code>.Close()
Richard Deeming 30-Sep-19 9:16am
   
Shouldn't be required for a DataAdapter - it will open and close the connection for you automatically.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

I found the cause by starting with an empty database and adding each column and testing for a change and save after each new column is added. All changed and saved OK until I added a date column and this caused the concurrency error even though I was not making any changes to the column. I am therefore assuming (dangerous I know!) that between when the sqliteadapter fills the datatable from the database file and when the sqliteadapter updates the database from the datatable it is thinking the date has been changed, so I will look into how vb.net and sqlite handle dates.
Thanks for your input.
Brad
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100