Strange new concurrency issue

E

Earl

My Update logic worked .. and now it doesn't. I went back, examined the
stored procedure carefully, examined the table structure carefully, and
examined the parameters collection carefully. All names, datatypes, and
sizes match up. In this particular table, all values can be set to Null
except for the primary key, SalesID. So as part of my testing to ensure the
data itself wasn't the cause of the error, I tried Updating all DBNull
values to every column except for the primary key ... still no success.

The dataset is global, and the datatable is dimmed Private to the form
class.
The datatable shows a count of 1 row right before I try to update.
The dataset returns True on HasChanges right before I try to submit the
update.
All parameters in the Update function match perfectly with the stored
procedure.

I've used similar logic in more than a dozen forms in the same app, but I'm
stumped -- everything looks correct, but I still get a "Concurrency error,
no records have been updated" when it hits the da.Update(dsChanges,
"dtSales") command. Anyone see anything?

Try-catch removed for readability.
**********************************************
Dim strSQLServer As New SqlConnection(strConnString)
strSQLServer.Open()

dtSales = ds.Tables("dtSales")

Dim m_intSalesID As Int32 = CInt(dtSales.Rows(0)("SalesID"))

dtSales.Rows(0)("SalesID") = m_intSalesID
.....
'(all remaining fields set to DbNull)

Dim dsChanges As DataSet
dsChanges = ds.GetChanges

Dim da As New SqlDataAdapter

' CreateSaleUpdate() is a function that returns a command with all
parameters

da.UpdateCommand = CreateSaleUpdate()
da.Update(dsChanges, "dtSales")

ds.AcceptChanges()

strSQLServer.Close()
 
M

Marina

It looks like you are taking the PK column, and setting it to itself. This
markes that column as having been changed (even though it got set to the
same value). Potentially this is causing the problem. I'm not exactly sure
why you would want to do this anyway? It's just extra work.

Also, you don't need to call AcceptChanges after Update. Update does that
already.
 
E

Earl

Thanks for the ideas Marina. I'm only using the PK to check for identity. It
isn't set in the sproc. I had even dropped it to see if that *was* an issue
and nope. I'm getting the error before it hits AcceptChanges, at the point
where the dataadapter tries to submit the changes.
 
K

Kevin Yu [MSFT]

Hi Earl,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you're having trouble when updating the
datasource using ADO.NET. If there is any misunderstanding, please feel
free to let me know.

I have checked the code you have provided, it seems to be working fine to
me. So could you please provide me with more information about the stored
procedure code and CreateSaleUpdate code? From the exception message, it
seems that something is preventing ADO.NET from finding the original
record. So that the concurrency exception is thrown.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

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