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 ..