views:

253

answers:

2

I would like to update a list item using SharePoint and am stuggling to find 1 decent CAML example.

Here is what I want to do, in SQL my query would look something like this

update [table] set field='value' where fieldID = id;

so this would mean I have 1 item in a list I would like to update 1 field on given the ID of that listitem.

I've tried this, but it doesn't work:

batchElement.InnerXml = "<Method ID='1' Cmd='Update'>" +
            "<Field Name='DeliveryStatus'>" + newStatus.ToString() + "</Field>" +
            "<Where><Eq><FieldRef Name='ID' /><Value Type='Text'>" + id + "</Value></Eq></Where></Method>";
A: 

I'll add this answer for the community, although it might not answer all your questions.

 batchElement.InnerXml = "<Method ID='1' Cmd='Update'>" +
                "<Field Name='ID'>" + id + "</Field>" + 
            "<Field Name='DeliveryStatus'>" + newStatus.ToString() + "</Field></Method>";

It seems the first field you specify is the where clause.

I have no idea how you would do any advanced filtering with this (nots or exclusions or in clauses or ranges). But hope this basic info helps.

JL
A: 

You don't need use the where clause to update a list item.

atchElement.InnerXml = "<Method ID='1' Cmd='Update'>" +
            "<Field Name='DeliveryStatus'>" + newStatus.ToString() + "</Field>" +
            "<FieldRef Name='ID' /><Value Type='Text'>" + id + "</Value></Method>";

The only think you need do is to provide the ID like above.

Yongwei Xing
What if you wanted to update all items, lets say that had a field Enabled - with values set to true?
JL
@JL I think you need update the items in a loop. I have not done it before.
Yongwei Xing