Click here to Skip to main content
15,885,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi , i want to ask that how can we insert list item in share point existing list using CAML and SPQuery.Query in server object model , is their any way to write query to insert and update it i have read and delete the item using this but i can't find any means to do add and update .. the code is :

XML
SPWeb mySite = SPContext.Current.Web;

            SPList li = mySite.Lists["List"];

            SPQuery oQuery = new SPQuery();

            oQuery.Query = string.Concat("<Where><Eq>",
                                                    "<FieldRef Name='ID'/>",
                                                    "<Value Type='Number'>", TextBox7.Text.ToString() ,"</Value>",
                                         "</Eq></Where>");





            oQuery.ViewFields = string.Concat(
                                   "<FieldRef Name='ID'/>",
                                   "<FieldRef Name='Title'/>",
                                   "<FieldRef Name='Email'/>",
                                   "<FieldRef Name='Department'/>");

            oQuery.ViewFieldsOnly = true;


            SPListItemCollection collListItems = li.GetItems(oQuery);

            int j = collListItems.Count;

            for (int i = 0; i < j; i++)
            {
                collListItems[0].Delete();
                cc.Text = "Deleted";
            }



Also , i have found this while searching for the solution

XML
<Batch OnError="Continue">
        <Method ID="1" Cmd="New">
         <Field Name="WikiField">My Wiki Content</Field>
        </Method>
      </Batch>



please assist me with your solutions and ideas ?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900