Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Error While Updating List item

  Asked By: Nagendra    Date: Jan 14    Category: Sharepoint    Views: 2035

I am trying to update the shapoint list item from web application.. I am
using following code to do the same. While executing the itemDt..Update()
statement it is throwing error as "Unable to evaluate expression because the
code is optimized or a native frame is on top of the call stack.." If any body
have solution please reply to me as soon as possible.

Code :
SPListItemCollection listItems;
SPSite queuemanagement = new SPSite("Site URL");
SPWeb web = queuemanagement.OpenWeb();
SPList listDt = web.Lists["List Name"];
SPQuery query = new SPQuery();

string sReportName = ReportID.Value;
int reqId = Convert.ToInt32(ViewState["RequestId"]);
query.Query = "<Where><Eq><FieldRef Name='ID' /><Value
Type='Number'>" + reqId + "</Value></Eq></Where>";
listItems = listDt.GetItems(query);
if (listItems.Count > 0)
for (int i = 0; i < listItems.Count; i++)
SPListItem itemDt = listItems[i];
itemDt["Similar_x0020_Report_x0020_Name"] =

web.AllowUnsafeUpdates = true;
web.AllowUnsafeUpdates = false;
catch (Exception ex)



1 Answer Found

Answer #1    Answered By: Karin Kerr     Answered On: Jan 14

I don't see anything specific that would cause your code  to fail, and broken
inheritance in code before. But there are several changes that should be made
to the code. Try these and see if your code works better.

1) When processing a collection in SharePoint you should use a Foreach
instead of a For. Foreach is more efficient in a SharePoint environment.

2) I would Breakinheritance BEFORE you change the properties of the object.

3) Unless you are doing this inside an XML webservice you don't need the
AllowUnsafeUpdates calls. But you should use a disableEventFiring call.

Didn't find what you were looking for? Find more on Error While Updating List item Or get search suggestion and latest updates.