Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Iam using SQL Server 2012. When I try to save my records it's giving the "Concurrency Violation - The update command affected 0 of 1 records". This error occours only when I save from DataGridView DataSource... Also, once I save to another DataTable and after update, it's working fine. But it's not updating from DataGridView's DataSource. Thanks For the Guidance’s // Once I added the below codes, Its' Working fine Since Iam curious, while the error giving only for DGVDtb [ DGV Data Table], but not for NewDtb.
C++
DataTable^ NewDtb = gcnew DataTable();
NewDtb->Columns->Add("emp_id", Type::GetType("System.String"));
NewDtb->Columns->Add("iqama_no", Type::GetType("System.String"));
NewDtb->Columns->Add("iqama_place_iss", Type::GetType("System.String"));


// Then The Data Store to NewDtb, it's working fine... But If I try from DGVDtb it's
not working And giving the Concurrency error for update
C++
InsSavCmd = "Insert into emp_legaldocmst (emp_id,iqama_no,iqama_place_iss) values (@emp_id,@iqama_no,@iqama_place_iss)";
UpdtSavCmd = "Update emp_legaldocmst set iqama_no=@iqama_no,iqama_place_iss=@iqama_place_iss where emp_id=@emp_id";

MyGlobalData::HR_Con->ConnectionString = MyGlobalData::HRCon_1;
MyGlobalData::HR_Con->Open();
    SqlTransaction^ Trans = MyGlobalData::HR_Con->BeginTransaction();
    MyGlobalData::DAp->UpdateCommand->Transaction = Trans;
    MyGlobalData::DAp->InsertCommand->Transaction = Trans;
    MyGlobalData::DAp->RowUpdating += gcnew SqlRowUpdatingEventHandler(Form1::OnRowUpdating);
    myDataGrid1->CurrentCell = myDataGrid1->FirstDisplayedCell;
    myDataGrid1->EndEdit();
    try {
         MyGlobalData::DAp->Update(DGVDtb);
         //MyGlobalData::DAp->Update(NewDtb);  **** Its working Fine ***********
         Trans->Commit();
         MySavMessg="EMPLOYEE LEGAL DOCUMENT MASTER - UPDATE STATUS : SUCCESS";
        } catch (System::Exception^ ex) {
        MySavMessg="EMPLOYEE LEGAL DOCUMENT MASTER HAS NOT UPDATED : STATUS - FAIL : " +ex->Message;
        }
        MyGlobalData::HR_Con->Close();
Posted
Comments
Philippe Mori 14-Dec-13 8:21am    
It look like you are saving a row that was not modified (or that was already saved)...
The_Inventor 15-Dec-13 20:41pm    
Are you trying to update data in DGVDtb at the same time it is open? I presume you executed the same command DataTable^ DGVDtb = gcnew DataTable(); someplace else for DGVDtb.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900