none
Concurrency violation: the DeleteCommand affected 0 of the expected 1 records. RRS feed

  • Question

  • Hi all
    I Saved a record by this code

      With bsAmountActionItem
                .AddNew()
                .Current.Item("AmountActionHeaderRef") = 1 & txtAmountActionNum.Text
                .Current.Item("IsAccounting") = 0
                .Current.Item("AccountDetailRef") = txtAccountDetailRef.Text
                If String.IsNullOrEmpty(txtFishNum.Text) = False Then .Current.Item("FishNum") = txtFishNum.Text
                If txtFishDate.Text <> Nothing Then .Current.Item("FishDate") = txtFishDate.Text
                .Current.Item("Debit") = Double.Parse(txtDebit.Text, Globalization.NumberStyles.Any)
                .Current.Item("Credit") = 0
                If String.IsNullOrEmpty(txtComment.Text.Trim) = False Then .Current.Item("Comment") = txtComment.Text.Trim
                .EndEdit()
            End With
            AmountActionItemTableAdapter.Update(Ds.AmountActionItem)


    now when i want delete this record
    i used this code

      bsAmountActionItem.Current.Delete()
            AmountActionItemTableAdapter.Update(Ds.AmountActionItem)   
    // Error has been occured in this line

    but i see this error

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

    how to solve this problem

    thanks all


    Name of Allah, Most Gracious, Most Merciful and He created the human



    • Edited by sh 2020 Sunday, July 29, 2012 2:33 PM
    Sunday, July 29, 2012 2:27 PM

Answers

  • solve the problem

    i remove my datatable in dataset

    and add new datatable 


    Name of Allah, Most Gracious, Most Merciful and He created the human

    • Marked as answer by sh 2020 Sunday, July 29, 2012 5:13 PM
    Sunday, July 29, 2012 5:13 PM

All replies

  • Try putting an bsAmountActitionItem.EndEdit() after the .Delete().  That might do the trick.

    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com


    • Edited by BonnieBMVP Sunday, July 29, 2012 4:16 PM
    Sunday, July 29, 2012 4:15 PM
  • i add this line:

    bsAmountActitionItem.EndEdit() after

    and see this error:


    Name of Allah, Most Gracious, Most Merciful and He created the human

    Sunday, July 29, 2012 4:28 PM
  • That error means that the record you're trying to delete in the database doesn't exist in the databse. There could be several reasons for that. See if this link helps at all:

    http://social.msdn.microsoft.com/Forums/en/adodotnetdataset/thread/3e431a0c-6a06-411e-8c8e-fd13a911b2c4

    Next thing you should look at is what the TableAdapter's DeleteCommand looks like at runtime. Try putting a breakpoint in your TableAdapter code to look at the command and the parameters. Perhaps your DataTable doesn't have the PrimaryKey of the newly added row that you're trying to delete?


    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Sunday, July 29, 2012 4:44 PM
  • That error means that the record you're trying to delete in the database doesn't exist in the databse.


    thanks dear 

    but i see my record in datagrid


    Name of Allah, Most Gracious, Most Merciful and He created the human

    Sunday, July 29, 2012 4:51 PM
  • my datatable in dataset is:

    and get record from database into datagridview


    Name of Allah, Most Gracious, Most Merciful and He created the human


    • Edited by sh 2020 Sunday, July 29, 2012 4:56 PM insert pics
    Sunday, July 29, 2012 4:53 PM
  • but i see my record in datagrid

    The DataTable, as displayed in the grid, is not the database.  ;0)

    Try looking at the command at runtime by setting a breakpoint and debugging. It would be helpful if you could also look at the data in the database at the same time.


    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Sunday, July 29, 2012 4:56 PM
  • I SELECT into sql server by this code

    and see a record into database that i see in the datatable or datagrid???


    Name of Allah, Most Gracious, Most Merciful and He created the human

    Sunday, July 29, 2012 5:05 PM
  • solve the problem

    i remove my datatable in dataset

    and add new datatable 


    Name of Allah, Most Gracious, Most Merciful and He created the human

    • Marked as answer by sh 2020 Sunday, July 29, 2012 5:13 PM
    Sunday, July 29, 2012 5:13 PM
  • I wonder if your schema changed in your database since you first created your DataSet? And maybe the TableAdapter was out of sync with the database table? I'm just guessing as to the probable cause of the problem, based on the fact that recreating your DataTable solved the problem.

    I don't use TableAdapters ... preferring to have more control of my database updates, I use the DataAdapters.


    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Monday, July 30, 2012 4:56 AM