Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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;
                }
            }
        }
share|improve this question
    
Whats the error and your accept rate is very low, try to increase it. –  Muhammad Raja Dec 23 '12 at 8:37
    
well if i wont get the proper answer how would I accept it? People just put answers here which sometime makes no sense so just to increase my accept rate you want me to accept it? Plus the error is on first line which you didnt notice. –  user342944 Dec 23 '12 at 15:53
    
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
add comment

1 Answer

up vote 2 down vote accepted

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();
share|improve this answer
    
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 Sharepoint Dec 24 '12 at 9:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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