Update Sharepoint List Item

前端 未结 4 921
耶瑟儿~
耶瑟儿~ 2020-12-15 00:31

I got following error...

System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.SharePoint.SPListItem.get

4条回答
  •  醉梦人生
    2020-12-15 01:11

    Ruben's answer was correct but was getting few errors (may be its was only for me) therefore i tweaked little bit and then it was working fine. Below is the code which i used if anyone needs it

     SPList list = web.Lists["ListName"];
                        //SPListItem item = list.Items.Add();
                        //item["PercentComplete"] = .45; 
                        // 45%//item.Update();
                       SPQuery oQuery = new SPQuery();
    
                            oQuery.Query = @"               
                                                           
                                                               
                                            Design              
                                                    
                                      ";
                            SPListItemCollection collListItems = list.GetItems(oQuery);
                            foreach (SPListItem item in collListItems)
                        {    item["PercentComplete"] = .55;   
                            item.Update();}
    

提交回复
热议问题