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 the following code

    protected void BetOnCar_Click(object sender, EventArgs e)
    {
        DerbyDataContext context = new DerbyDataContext(SPContext.Current.Web.Url);
        int carId = Int32.Parse(SelectedCarId.Value);
        int totalBets = Int32.Parse(TotalBets.Text);
        Item car = context.Cars.FirstOrDefault(c => c.Id == carId);
        for (int i = 0; i < totalBets; i++)
        {
            var bet = new BetItem();
            bet.BetterId = SPContext.Current.Web.CurrentUser.ID;
            bet.Car = (CarsPicture)car;
            bet.Title = "Car Bet";
            context.Bet.InsertOnSubmit(bet);                
        }
        context.SubmitChanges();

    }

(I had the car as var car = ....... before but changed it to item and casted it as I found a post saying that was a solution but that did nothing for me) And when it tries to submit changes it gets the following error

<nativehr>0x80070057</nativehr><nativestack></nativestack>Invalid data has been used to update the list item. The field you are trying to update may be read only.

I have tried allowing unsafe update on site and web but still nothing. If I remove the car part then it works. Car is from a picture library if that matters.

EDIT: Whats really weird is that it is somewhat working. I went to the list and I can see the correct values in the lookup column. But still it is throwing an exception. Worse case I could catch and ignore the exception but that just sounds horrible ..

share|improve this question
    
did you web.update(); after the allow unsafe updates? Also look at this a similar issue here also 2010 social.technet.microsoft.com/Forums/en-US/… –  Hugh Wood Sep 6 '12 at 16:02
    
I did not but I went back and added that and it didn't help. He is getting a similiar error, and it may be related but he is just trying to deploy the solution. While I am trying to use the SPMetal classes to add a EntityItem to another EntityItem and getting the error. –  Josh Sep 6 '12 at 19:35
    
I have the same problem, the only UGLY way to avoid this is giving contribution permissions on the referenced list to the user who is executing the insert action.. sometimes I just hate Sharepoint –  user11299 Oct 11 '12 at 20:42
    
If this was a permissions issue there would be no partial field content. The OP says some of the fields update, some don't. –  RJ Cuthbertson Oct 12 '12 at 2:58

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.