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

  • Question

  • hi all

    I use this code for edit a record

     Private Sub btnEdit_Click(sender As System.Object, e As System.EventArgs) Handles btnEdit.Click
            If Check_ObjectItem() = False Then Exit Sub
            Using Cmd As New SqlClient.SqlCommand(Nothing, Cn)
                If Cn.State = ConnectionState.Closed Then Cn.Open()
                Cmd.CommandText = String.Format("UPDATE ProductActionItem SET UserRef={0},InDate='{1}',Price={2},Total={3},Comment='{4}' WHERE ProductActionItemId={5} ",
                                                                             UserId, Calender.TodayInIran & Space(1) & Now.ToLongTimeString, Double.Parse(txtPrice.Text, Globalization.NumberStyles.Any), Double.Parse(txtTotal.Text, Globalization.NumberStyles.Any), txtComment.Text, dblProductActionItemId)
                Cmd.ExecuteNonQuery()
                Cn.Close()
            End Using
    
    
            With FrmProductAction2
                .DataGridViewX2.CurrentRow.Cells(4).Value = Double.Parse(txtPrice.Text, Globalization.NumberStyles.Any)
                .DataGridViewX2.CurrentRow.Cells(5).Value = Double.Parse(txtTotal.Text, Globalization.NumberStyles.Any)
                .DataGridViewX2.CurrentRow.Cells(6).Value = txtComment.Text
                .Sum_Items()
                .Save_Header_By_Total()
                .Sum_Debit()
            End With
            Me.Close()
        End Sub

    after changes  record i want to save a new record by this codes...

      Private Sub ItemSave()
            With bsProductActionItem
                .AddNew()
                .Current.Item("ProductActionHeaderRef") = 2 & txtProductActionHeaderNum.Text
                .Current.Item("UserRef") = UserId
                .Current.Item("InDate") = Calender.TodayInIran & Space(1) & Now.ToLongTimeString
                If ChkWith.Checked = True Then .Current.Item("InstructionHeaderRef") = txtInstructionHeaderRef.Text
                .Current.Item("ProductRef") = txtProductRef.Text
                .Current.Item("Quanty") = txtQuanty.Text
                .Current.Item("Price") = Double.Parse(txtPrice.Text, Globalization.NumberStyles.Any)
                .Current.Item("Total") = Double.Parse(txtTotal.Text, Globalization.NumberStyles.Any)
                If String.IsNullOrEmpty(txtComment.Text.Trim) = False Then .Current.Item("Comment") = txtComment.Text.Trim
                .EndEdit()
            End With
            ProductActionItem2TableAdapter.Update(DsMbsPerlika.ProductActionItem2)
            EmptyObjectItem()
            Sum_Items()
            btnSaveEF.PerformClick()
        End Sub

    but i see an error in this line

     ProductActionItem2TableAdapter.Update(DsMbsPerlika.ProductActionItem2)

    how to solve this problem

    please help me

    thanks


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

    Thursday, August 9, 2012 7:20 AM

Answers

  • Hi sh2013,

    Did you get the DsMbsPerlika.ProductActionItem2 before you update the record?

    If so, please try to refill the DsMbsPerlika.ProductActionItem2 table before you modify it.

    If the issue still not solved, could you please post the insert command of the ProductActionItem2TableAdapter?

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, August 10, 2012 9:30 AM
    Moderator

All replies

  • dear BonnieB 

    Please help me



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

    Thursday, August 9, 2012 1:34 PM
  • Hi sh2013,

    Did you get the DsMbsPerlika.ProductActionItem2 before you update the record?

    If so, please try to refill the DsMbsPerlika.ProductActionItem2 table before you modify it.

    If the issue still not solved, could you please post the insert command of the ProductActionItem2TableAdapter?

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, August 10, 2012 9:30 AM
    Moderator