PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2015 [RESOLVED] Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.-VBForums
Results 1 to 11 of 11

Thread: [RESOLVED] Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Resolved [RESOLVED] Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

    vb.net Code:
    1. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    2.         bind2.EndEdit()
    3.         bind1.EndEdit()
    4.  
    5.         Dim insercommand As New OleDb.OleDbCommand("INSERT INTO members (family_ID, person_role, pname, birthdate, Qualification, job, tel, religion, handicap, comments) values (@family_ID, @person_role, @pname, @birthdate, @Qualification, @job, @tel, @religion, @handicap, @comments)", classcon.con)
    6.         insercommand.Parameters.Add("@family_ID", OleDb.OleDbType.Integer)
    7.         insercommand.Parameters.Add("@person_role", OleDb.OleDbType.VarChar)
    8.         insercommand.Parameters.Add("@pname", OleDb.OleDbType.VarChar)
    9.         insercommand.Parameters.Add("@birthdate", OleDb.OleDbType.Date)
    10.         insercommand.Parameters.Add("@Qualification", OleDb.OleDbType.VarChar)
    11.         insercommand.Parameters.Add("@job", OleDb.OleDbType.VarChar)
    12.         insercommand.Parameters.Add("@tel", OleDb.OleDbType.VarChar)
    13.         insercommand.Parameters.Add("@religion", OleDb.OleDbType.VarChar)
    14.         insercommand.Parameters.Add("@handicap", OleDb.OleDbType.Boolean)
    15.         insercommand.Parameters.Add("@comments", OleDb.OleDbType.VarChar)
    16.         damembers.InsertCommand =insercommand
    17.  
    18.         Dim updatecommand As New OleDb.OleDbCommand("UPDATE members SET person_role = @person_role, pname = @pname, birthdate = @birthdate, Qualification = @Qualification, job = @job, tel = @tel, religion = @religion, handicap = @handicap, comments = @comments where family_ID = @family_ID", classcon.con)
    19.         updatecommand.Parameters.Add("@family_ID", OleDb.OleDbType.Integer, 0, "family_ID")
    20.         updatecommand.Parameters.Add("@person_role", OleDb.OleDbType.VarChar, 0, "person_role")
    21.         updatecommand.Parameters.Add("@pname", OleDb.OleDbType.VarChar, 0, "pname")
    22.         updatecommand.Parameters.Add("@birthdate", OleDb.OleDbType.Date, 0, "birthdate")
    23.         updatecommand.Parameters.Add("@Qualification", OleDb.OleDbType.VarChar, 0, "Qualification")
    24.         updatecommand.Parameters.Add("@job", OleDb.OleDbType.VarChar, 0, "job")
    25.         updatecommand.Parameters.Add("@tel", OleDb.OleDbType.VarChar, 0, "tel")
    26.         updatecommand.Parameters.Add("@religion", OleDb.OleDbType.VarChar, 0, "religion")
    27.         updatecommand.Parameters.Add("@handicap", OleDb.OleDbType.Boolean, 0, "handicap")
    28.         updatecommand.Parameters.Add("@comments", OleDb.OleDbType.VarChar, 0, "comments")
    29.  
    30.         damembers.UpdateCommand = updatecommand
    31.  
    32.         damembers.MissingSchemaAction = MissingSchemaAction.AddWithKey
    33.         damembers.Update(dtmembers)
    34.     End Sub
    i get that error when i update record

    Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,689

    Re: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

    Under what circumstances exactly do you get that error message? Is it maybe if you insert a new record and then edit it and try to save a second time?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

    no just update existing record






  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,689

    Re: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

    I'm not sure that this is related but why are you setting the size of all your varchar parameters to 0? Didn't we cover that in another thread? Yes, we did.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

    yes but i dont know the exact size

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

    vb.net Code:
    1. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    2.         bind2.EndEdit()
    3.         bind1.EndEdit()
    4.  
    5.         Dim insercommand As New OleDb.OleDbCommand("INSERT INTO members (family_ID, person_role, pname, birthdate, Qualification, job, tel, religion, handicap, comments) values (@family_ID, @person_role, @pname, @birthdate, @Qualification, @job, @tel, @religion, @handicap, @comments)", classcon.con)
    6.         insercommand.Parameters.Add("@family_ID", OleDb.OleDbType.Integer)
    7.         insercommand.Parameters.Add("@person_role", OleDb.OleDbType.VarChar)
    8.         insercommand.Parameters.Add("@pname", OleDb.OleDbType.VarChar)
    9.         insercommand.Parameters.Add("@birthdate", OleDb.OleDbType.Date)
    10.         insercommand.Parameters.Add("@Qualification", OleDb.OleDbType.VarChar)
    11.         insercommand.Parameters.Add("@job", OleDb.OleDbType.VarChar)
    12.         insercommand.Parameters.Add("@tel", OleDb.OleDbType.VarChar)
    13.         insercommand.Parameters.Add("@religion", OleDb.OleDbType.VarChar)
    14.         insercommand.Parameters.Add("@handicap", OleDb.OleDbType.Boolean)
    15.         insercommand.Parameters.Add("@comments", OleDb.OleDbType.VarChar)
    16.         damembers.InsertCommand =insercommand
    17.  
    18.         Dim updatecommand As New OleDb.OleDbCommand("UPDATE members SET person_role = @person_role, pname = @pname, birthdate = @birthdate, Qualification = @Qualification, job = @job, tel = @tel, religion = @religion, handicap = @handicap, comments = @comments where family_ID = @family_ID", classcon.con)
    19.         updatecommand.Parameters.Add("@family_ID", OleDb.OleDbType.Integer)
    20.         updatecommand.Parameters.Add("@person_role", OleDb.OleDbType.VarChar)
    21.         updatecommand.Parameters.Add("@pname", OleDb.OleDbType.VarChar)
    22.         updatecommand.Parameters.Add("@birthdate", OleDb.OleDbType.Date)
    23.         updatecommand.Parameters.Add("@Qualification", OleDb.OleDbType.VarChar)
    24.         updatecommand.Parameters.Add("@job", OleDb.OleDbType.VarChar)
    25.         updatecommand.Parameters.Add("@tel", OleDb.OleDbType.VarChar)
    26.         updatecommand.Parameters.Add("@religion", OleDb.OleDbType.VarChar)
    27.         updatecommand.Parameters.Add("@handicap", OleDb.OleDbType.Boolean)
    28.         updatecommand.Parameters.Add("@comments", OleDb.OleDbType.VarChar)
    29.  
    30.         damembers.UpdateCommand = updatecommand
    31.  
    32.         damembers.MissingSchemaAction = MissingSchemaAction.AddWithKey
    33.         damembers.Update(dtmembers)
    34.     End Sub

    when i try it this way i get this error
    Parameter @person_role has no default value.

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,689

    Re: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

    Quote Originally Posted by new1 View Post
    yes but i dont know the exact size
    Why not? It's your database isn't it? Find out.

  8. #8
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,689

    Re: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

    Quote Originally Posted by new1 View Post
    vb.net Code:
    1. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    2.         bind2.EndEdit()
    3.         bind1.EndEdit()
    4.  
    5.         Dim insercommand As New OleDb.OleDbCommand("INSERT INTO members (family_ID, person_role, pname, birthdate, Qualification, job, tel, religion, handicap, comments) values (@family_ID, @person_role, @pname, @birthdate, @Qualification, @job, @tel, @religion, @handicap, @comments)", classcon.con)
    6.         insercommand.Parameters.Add("@family_ID", OleDb.OleDbType.Integer)
    7.         insercommand.Parameters.Add("@person_role", OleDb.OleDbType.VarChar)
    8.         insercommand.Parameters.Add("@pname", OleDb.OleDbType.VarChar)
    9.         insercommand.Parameters.Add("@birthdate", OleDb.OleDbType.Date)
    10.         insercommand.Parameters.Add("@Qualification", OleDb.OleDbType.VarChar)
    11.         insercommand.Parameters.Add("@job", OleDb.OleDbType.VarChar)
    12.         insercommand.Parameters.Add("@tel", OleDb.OleDbType.VarChar)
    13.         insercommand.Parameters.Add("@religion", OleDb.OleDbType.VarChar)
    14.         insercommand.Parameters.Add("@handicap", OleDb.OleDbType.Boolean)
    15.         insercommand.Parameters.Add("@comments", OleDb.OleDbType.VarChar)
    16.         damembers.InsertCommand =insercommand
    17.  
    18.         Dim updatecommand As New OleDb.OleDbCommand("UPDATE members SET person_role = @person_role, pname = @pname, birthdate = @birthdate, Qualification = @Qualification, job = @job, tel = @tel, religion = @religion, handicap = @handicap, comments = @comments where family_ID = @family_ID", classcon.con)
    19.         updatecommand.Parameters.Add("@family_ID", OleDb.OleDbType.Integer)
    20.         updatecommand.Parameters.Add("@person_role", OleDb.OleDbType.VarChar)
    21.         updatecommand.Parameters.Add("@pname", OleDb.OleDbType.VarChar)
    22.         updatecommand.Parameters.Add("@birthdate", OleDb.OleDbType.Date)
    23.         updatecommand.Parameters.Add("@Qualification", OleDb.OleDbType.VarChar)
    24.         updatecommand.Parameters.Add("@job", OleDb.OleDbType.VarChar)
    25.         updatecommand.Parameters.Add("@tel", OleDb.OleDbType.VarChar)
    26.         updatecommand.Parameters.Add("@religion", OleDb.OleDbType.VarChar)
    27.         updatecommand.Parameters.Add("@handicap", OleDb.OleDbType.Boolean)
    28.         updatecommand.Parameters.Add("@comments", OleDb.OleDbType.VarChar)
    29.  
    30.         damembers.UpdateCommand = updatecommand
    31.  
    32.         damembers.MissingSchemaAction = MissingSchemaAction.AddWithKey
    33.         damembers.Update(dtmembers)
    34.     End Sub

    when i try it this way i get this error
    Parameter @person_role has no default value.
    Well, that's because that's not the right way to do it. I've directed you to a CodeBank thread of mine that demonstrates the right way to do it. Have you bothered to read that? If you're going to ignore the advice I provide then you're wasting my time and, frankly, yours too.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

    Retrieving multiple records for display and editing, then saving the changes

    your code:
    vb.net Code:
    1. Private Sub InitialiseDataAdapter()
    2.         Dim update As New SqlCommand("UPDATE StockItem SET Name = @Name, Quantity = @Quantity, Unit = @Unit WHERE ID = @ID", Me.connection)
    3.      
    4.     update.Parameters.Add("@Name", SqlDbType.VarChar, 100, "Name")
    5.     update.Parameters.Add("@Quantity", SqlDbType.Float, 8, "Quantity")
    6.     update.Parameters.Add("@Unit", SqlDbType.VarChar, 10, "Unit")
    7.     update.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
    8.  
    9.         Me.adapter.UpdateCommand = update
    10.  
    11.     Me.adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
    12. End Sub
    13.  
    14. Private Sub SaveData()
    15.     'Save the changes.
    16.     Me.adapter.Update(Me.table)
    17. End Sub
    18. End Sub

    my code:
    vb.net Code:
    1. Dim updatecommand As New OleDb.OleDbCommand("UPDATE members SET person_role = @person_role, pname = @pname, birthdate = @birthdate, Qualification = @Qualification, job = @job, tel = @tel, religion = @religion, handicap = @handicap, comments = @comments where family_ID = @family_ID", classcon.con)
    2.          updatecommand.Parameters.Add("@person_role", OleDb.OleDbType.VarChar)
    3.         updatecommand.Parameters.Add("@pname", OleDb.OleDbType.VarChar)
    4.         updatecommand.Parameters.Add("@birthdate", OleDb.OleDbType.Date)
    5.         updatecommand.Parameters.Add("@Qualification", OleDb.OleDbType.VarChar)
    6.         updatecommand.Parameters.Add("@job", OleDb.OleDbType.VarChar)
    7.         updatecommand.Parameters.Add("@tel", OleDb.OleDbType.VarChar)
    8.         updatecommand.Parameters.Add("@religion", OleDb.OleDbType.VarChar)
    9.         updatecommand.Parameters.Add("@handicap", OleDb.OleDbType.Boolean)
    10.         updatecommand.Parameters.Add("@comments", OleDb.OleDbType.VarChar)
    11.         updatecommand.Parameters.Add("@family_ID", OleDb.OleDbType.Integer)
    12.  
    13.         damembers.UpdateCommand = updatecommand
    14.  
    15.         damembers.MissingSchemaAction = MissingSchemaAction.AddWithKey
    16.         damembers.Update(dtmembers)


    hope you can tell me where is the wrong

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

    what is the field size as integer in vb.net for

    access database field: number, short text, date/time, yes/no, long text

  11. #11
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,689

    Re: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

    Quote Originally Posted by new1 View Post
    hope you can tell me where is the wrong
    My Parameters.Add calls have four arguments while yours have two. The fourth argument is the name of the DataColumn from which to get the data. You're not going to save any data if the data adapter doesn't know where to get that data from.
    Last edited by jmcilhinney; Oct 1st, 2016 at 11:22 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width