• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

Error when trying to update a dataset

Update dataset on change.   I am running the code below so that whenever there is a change to the textbox it updates.   My problem is that I sometimes get update errors.    saying Command0 cannot update.  Can anyone give me an idea what is might be?  Thanks

Dspat1.Tables("tblPatient").Rows(0).Item("strEmergencyName") = TextBox19.Text
        If TextBox19.Text <> "" Then
            If Dspat1.HasChanges Then
                Me.BindingContext(Dspat1.Tables(0)).EndCurrentEdit()
                SqlDataAdapter8.Update(Dspat1.Tables(0))
                Dspat1.AcceptChanges()
            End If
        End If
0
running32
Asked:
running32
  • 4
  • 3
1 Solution
 
Bob LearnedCommented:
What is the exact error message (stack trace)?

Bob
0
 
running32Author Commented:
I get the error Update Command Affected 0 records
0
 
Bob LearnedCommented:
Is it a concurrency exception?

Bob
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ArkCommented:
Did you specify Update command for dataadapter? If not, just add:
  Dim cmd_bilder as New SqlCommandBuilder(SqlDataAdapter8)
 
  Me.BindingContext(Dspat1.Tables(0)).EndCurrentEdit()
  SqlDataAdapter8.Update(Dspat1.Tables(0))
  Dspat1.AcceptChanges()
0
 
running32Author Commented:
Sorry for the delay.  I'll try that.  thanks.

Error is "Concurrency violation: the UpdateCommand affected 0 records.  "

thanks
0
 
Bob LearnedCommented:
This has a few causes:  1) You have multiple data sources accessing the same data, 2) misplaced AcceptChanges call that changes the primary key information.

Bob
0
 
running32Author Commented:
thanks Bob, misplaced AcceptChanges call that changes the primary key information.  Could you please explain a bit more.  Do you mean that I may be trying to update the Primary key?  thanks
0
 
Bob LearnedCommented:
I was just working on a project with a typed dataset, and TableAdapters, and I was using the Update method, and I got that exception.  The problem came down to a DataRow.AcceptChanges at the beginning of the process.  I was trying to get the update process to only write changes when something other than the first 3 columns were set (3 columns set when the DataRow was created).

Bob
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now