concurrency violation

  • Thread starter Adam Sim via .NET 247
  • Start date
A

Adam Sim via .NET 247

(Type your message here)

--------------------------------
From: Adam Sim

Hello, I am trying to update the data in an MS Access table using a Visual Basic Windows Application. The way I tried to do it has worked in the past, but now it seems to give a "concurrency violation."
if either the starred lines is in the code it produces a concurrency error, if they are not it does not produce an error but, of course, the original data is not changed. I have checked my table in access and it seems that all the formats are correct.

Thanks for your help

Adam

Here is the code:
Note: selid is a public variable for the case number of the record being worked upon


Sub save_art()

Dim strConnect As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& "C:\Documents and Settings\Owner\My Documents\Visual Studio Projects\mpqgrammar.mdb"
Dim cn1 As OleDbConnection = New OleDbConnection(strConnect)
cn1.Open()

Dim strSelectOut As String = _
"SELECT * FROM MPQFIN WHERE CASENO = " & selID
Dim dsOutCmd As New OleDbDataAdapter(strSelectOut, cn1)
Dim dsOutCmdBuild As OleDbCommandBuilder = New OleDbCommandBuilder(dsOutCmd)
Dim dsOut As New DataSet()
dsOutCmd.Fill(dsOut, "MPQFIN")

dsOut.Tables(0).Rows(0).Item("Done") = 1 '************
dsOut.Tables(0).Rows(0).Item("Coder") = userName '************
dsOutCmd.Update(dsOut, "MPQFIN")
cn1.Close()
MessageBox.Show("Record Saved!", "Save")
 
W

William Ryan eMVP

Hi Adam:

You are using a commandbuilder which has really limited ability to deal with
Concurrency. Check the update command that's being used b/c if it can't
find the row to update, it assumes that the value has been changed and
throws the concurrency exception. Are either of those keys, key values?
If you are changing the key that could be a problem. The main thing is
check the Update command and see what's happening there... that's the most
likley culprit. you may also want to consider getting rid of the
CommandBuilder..just a thought b/c your ability to deal with concurrency is
quite limited.

One last thing, I'd highly discourage the use of the Dynamic Concatenated
Sql... use Parameters instead, it's faster, safer, easier to maintian and
much less error prone. Just a thought.
Adam Sim via .NET 247 said:
(Type your message here)
Basic Windows Application. The way I tried to do it has worked in the past,
but now it seems to give a "concurrency violation."
if either the starred lines is in the code it produces a concurrency
error, if they are not it does not produce an error but, of course, the
original data is not changed. I have checked my table in access and it
seems that all the formats are correct.
Thanks for your help

Adam

Here is the code:
Note: selid is a public variable for the case number of the record being worked upon


Sub save_art()

Dim strConnect As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& "C:\Documents and Settings\Owner\My Documents\Visual
Studio Projects\mpqgrammar.mdb"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top