0

I have custom master detail form (ASPX)..i want to update masterblock and detail block in one function. i am doing like the following but getting below mentioned error. How can I update two lists items in one function.

Sharepoint Error: Save Conflict Your changes conflict with those made concurrently by another user

Here's My code

public void UpdateGridItem(int reqID, int gridItemId, string itemqty, string itemneedby, string finalRemarks)
        {
            string camlQueryDetail = @"<Where><And><Eq><FieldRef Name='Title' /><Value Type='Text'>"+reqID+"</Value></Eq><Eq><FieldRef Name='Item_x0020_ID' /><Value Type='Number'>" +gridItemId +" </Value></Eq></And></Where>";
            string camlQueryMaster = @"<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + reqID + "</Value></Eq></Where>";

            using (SPSite objSite = new SPSite(PortalUrl))
            {
                using (SPWeb objWeb = objSite.OpenWeb())
                {
                    objWeb.AllowUnsafeUpdates = true;

                    // Building a query
                    SPQuery query = new SPQuery();
                    SPQuery qMaster = new SPQuery();

                    query.Query = camlQueryDetail;
                    qMaster.Query = camlQueryMaster;

                    // Retrieving the data from the Detail List
                    SPList objList = objWeb.Lists["Requisition_Detail"];
                    SPListItemCollection items = objList.GetItems(query);

                    SPList objListMaster = objWeb.Lists["Requisition_Master"];
                    SPListItemCollection itemsMaster = objList.GetItems(qMaster);

                    SPListItem listItems = items[0];
                    SPListItem listItemsMaster = itemsMaster[0];

                    listItems["Quantity"] = Convert.ToInt32(itemqty);
                    listItems["Needed_By"] = itemneedby;
                    listItems.Update();

                    listItemsMaster["Header_Remarks"] = finalRemarks;                   
                    listItemsMaster.Update();

                    objWeb.AllowUnsafeUpdates = false;
                }
            }
        }
  • I know what you mean but I am trying to say that, if you find answers of your previous questions then you should answer them yourself – Muhammad Raja Dec 23 '12 at 16:19
  • i didn't know that i can answer it..thanks i will do it from now on..so what do you think about my question? – user342944 Dec 23 '12 at 16:27
2

If the sequence is the problem, try to do this:

                // Retrieving the data from the Detail List, Edit, Update
                SPList objList = objWeb.Lists["Requisition_Detail"];
                SPListItemCollection items = objList.GetItems(query);
                SPListItem listItems = items[0];
                listItems["Quantity"] = Convert.ToInt32(itemqty);
                listItems["Needed_By"] = itemneedby;
                listItems.Update();

                // Retrieving the data from the Master List, Edit, Update
                SPList objListMaster = objWeb.Lists["Requisition_Master"];
                SPListItemCollection itemsMaster = objList.GetItems(qMaster);
                SPListItem listItemsMaster = itemsMaster[0];
                listItemsMaster["Header_Remarks"] = finalRemarks;                   
                listItemsMaster.Update();
  • Thanks peter I never thought that sequence can be a obstacle..lesson learned :) – user342944 Dec 23 '12 at 20:14
  • any or most languages are procedural ;) unfortunatly your learned the hard way but its the best way of learning as it sticks in your head :) – Ali Jafer Dec 24 '12 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.