Hi Everyone,

Can you help me out of a concurrency violation error?

It happens on this statement:

objDataAdapterCustomerDetails.UpdateCommand = _
                    objCommandBuilderParentDetails.GetUpdateCommand

It thinks I'm using a key value of 1 when the actual value is really 1218.

I'm using a command builder and I'm also new to doing command builders so any help will be greatly appreciated.

The attachments show the value of the key value and the value of the update text values.

If you need it, I can post the code from the sub procedure that contains the command builder.

By the way, I can insert data but not update it.

Thanks.

Truly,
Emad

Recommended Answers

All 2 Replies

Hi,

Thanks for the link but the code just let me know the primary key value of the column giving the error. The primary key value was correct for the current row I was updating. Because I'm new to command builders I'm missing something. When I disabled the command builder and used this code I could update the data but can't figure out why command builders don't work for me.

' Have the command builder create an update SQL command.
                '-------------------------------------------------------
                ' objDataAdapterCustomerDetails.UpdateCommand = _
                'objCommandBuilderCustomerDetails.GetUpdateCommand()

                objDataAdapterCustomerDetails.UpdateCommand = objConnection.CreateCommand

                objDataAdapterCustomerDetails.UpdateCommand.CommandText = _
                    "Update Customers " & _
                       "SET FirstName = ?, LastName = ?, Address1 = ?, " & _
                           "Address2 = ?, City = ?, StateRegion = ?, zip = ?, " & _
                           "Notes = ?, PhoneHome = ?, PhoneCell = ?, PhoneWork = ?, " & _
                           "Email = ?, Spouse = ?, LocationOfPhoto = ?, " & _
                           "OtherID = ? " & _
                     "Where ID = ?"

                objDataAdapterCustomerDetails.UpdateCommand.Parameters. _
                    AddWithValue("FirstName", objDataRowCustomerDetails("FirstName"))

                objDataAdapterCustomerDetails.UpdateCommand.Parameters. _
                    AddWithValue("LastName", objDataRowCustomerDetails("LastName"))

                objDataAdapterCustomerDetails.UpdateCommand.Parameters. _
                    AddWithValue("Address1", objDataRowCustomerDetails("Address1"))

                objDataAdapterCustomerDetails.UpdateCommand.Parameters. _
                    AddWithValue("Address2", objDataRowCustomerDetails("Address2"))

                objDataAdapterCustomerDetails.UpdateCommand.Parameters. _
                    AddWithValue("City", objDataRowCustomerDetails("City"))

                objDataAdapterCustomerDetails.UpdateCommand.Parameters. _
                    AddWithValue("StateRegion", objDataRowCustomerDetails("StateRegion"))

                objDataAdapterCustomerDetails.UpdateCommand.Parameters. _
                    AddWithValue("Zip", objDataRowCustomerDetails("Zip"))

                objDataAdapterCustomerDetails.UpdateCommand.Parameters. _
                    AddWithValue("OtherID", objDataRowCustomerDetails("OtherID"))

                objDataAdapterCustomerDetails.UpdateCommand.Parameters. _
                    AddWithValue("Notes", objDataRowCustomerDetails("Notes"))

                objDataAdapterCustomerDetails.UpdateCommand.Parameters. _
                    AddWithValue("PhoneHome", objDataRowCustomerDetails("PhoneHome"))

                objDataAdapterCustomerDetails.UpdateCommand.Parameters. _
                    AddWithValue("PhoneCell", objDataRowCustomerDetails("PhoneCell"))

                objDataAdapterCustomerDetails.UpdateCommand.Parameters. _
                    AddWithValue("PhoneWork", objDataRowCustomerDetails("PhoneWork"))

                objDataAdapterCustomerDetails.UpdateCommand.Parameters. _
                    AddWithValue("Email", objDataRowCustomerDetails("Email"))

                objDataAdapterCustomerDetails.UpdateCommand.Parameters. _
                    AddWithValue("Spouse", objDataRowCustomerDetails("Spouse"))

                objDataAdapterCustomerDetails.UpdateCommand.Parameters. _
                    AddWithValue("LocationOfPhoto", objDataRowCustomerDetails("LocationOfPhoto"))

                objDataAdapterCustomerDetails.UpdateCommand.Parameters. _
                    AddWithValue("ID", intCustomerID)

            End If

Truly,
Emad

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.