About Me

My photo
a Dynamic and Energetic guy.....

Wednesday, October 29, 2008

Working With SPList & CAML Queries

SPWeb web = site.RootWeb;
SPList refList = web.Lists["refLstAAProgress"];
SPQuery
query = new SPQuery();


//
WITH MORE RESCRICTIONS

query.Query= "<Where><And><Eq><FieldRefName='colFormName' /><Value Type='Text'>" + pFormName +"</Value></Eq><Eq><FieldRef Name='colGroup'/><Value Type='Text'>"+ pGroupName+"</Value></Eq></And></Where>";


//
SIMPLE FILTERING

//query.Query= "<Where><Eq><FieldRef Name='SystemName'/><ValueType='Text'>" + pstrSystemName + "</Value></Eq></Where>";


SPListItemCollection collec = refList.GetItems(query);

//
UPDATE AN ENTRY

if (collec!= null && collec.Count > 0)


{

SPListItem itemEdit = collec[0];

itemEdit["colIsDone"]= "True";

web.AllowUnsafeUpdates= true;

itemEdit.SystemUpdate();

}


web.AllowUnsafeUpdates= false;

web.Dispose();

//ADD AN ITEM TO THE LIST


SPWeb web = site.RootWeb;

web.AllowUnsafeUpdates = false;
SPList
refList = web.Lists["refLstStageTracking"];
SPListItem
newListItem =logginList.Items.Add();
newListItem["Title"] ="GOGOGO";
newListItem["colFormName"] =pFromName;
newListItem["colStage"] = pStage;

newListItem["colLoginName"] = pLoginName;

newListItem.Update();

No comments:

My Masters