Learning: how to add data values to the list (development supplements rest)

Source: Internet
Author: User

Added support for ADO. net service in SharePoint 2010. We can add, query, or update data through rest. This articleArticle, I will try to use the rest method to query and add a record.

Preparation: getting startedCodeRemember to add a reference to the http: // servername/_ vti_bin/listdata. SVC service. After I reference it, I name it "listdatasr". Here is the detailed code. (I am in the consoleProgramTo run this code)

Listdatasr. spflearndatacontext CTX = New Listdatasr. spflearndatacontext ( New Uri ( "Http: // servername/_ vti_bin/listdata. SVC" )); Public   Void Addnewitem () {CTX. Credentials = credentialcache. defaultcredentials; listdatasr. jobsitem newjob = New Jobsitem (); newjob. Title ="SharePoint QA" ; Newjob. jobdescription = "QA in SharePoint Project" ; Newjob. cityvalue = "Shanghai" ; Newjob. duedate = datetime. Now. adddays (12); newjob. jobrequirementid = 2; newjob. managerid = 1; CTX. addtojobs (newjob); CTX. savechanges ();} Public   Void Getitems () {CTX. Credentials = credentialcache. defaultcredentials; var jobsinshanghai = from Q In CTX. Jobs Where Q. cityvalue = "Shanghai" Select Q; Foreach (VAR itemIn Jobsinshanghai) {console. writeline ( "Job title: {0}; Due Date {1}; city: {2 }" , Item. Title, item. duedate, item. cityvalue );}}

The three articles in this series are an accumulation and summary of yourself. Hope to help anyone who needs it.

 

Source: http://www.cnblogs.com/fanwenxuan/archive/2011/08/13/2137432.html

Added support for ADO. net service in SharePoint 2010. We can add, query, or update data through rest. In this article, I will try to use the rest method to query and add a record.

Preparation: before using the code, remember to add a reference to the http: // servername/_ vti_bin/listdata. SVC service. After I reference it, I name it "listdatasr". Here is the detailed code. (I am running this code in the console Program)

Listdatasr. spflearndatacontext CTX = New Listdatasr. spflearndatacontext ( New Uri ( "Http: // servername/_ vti_bin/listdata. SVC" )); Public   Void Addnewitem () {CTX. Credentials = credentialcache. defaultcredentials; listdatasr. jobsitem newjob = New Jobsitem (); newjob. Title = "SharePoint QA" ; Newjob. jobdescription = "QA in SharePoint Project" ; Newjob. cityvalue = "Shanghai" ; Newjob. duedate = datetime. Now. adddays (12); newjob. jobrequirementid = 2; newjob. managerid = 1; CTX. addtojobs (newjob); CTX. savechanges ();} Public   Void Getitems () {CTX. Credentials = credentialcache. defaultcredentials; var jobsinshanghai = from Q In CTX. Jobs Where Q. cityvalue = "Shanghai" Select Q; Foreach (VAR item In Jobsinshanghai) {console. writeline ( "Job title: {0}; Due Date {1}; city: {2 }" , Item. Title, item. duedate, item. cityvalue );}}

The three articles in this series are an accumulation and summary of yourself. Hope to help anyone who needs it.

 

Source: http://www.cnblogs.com/fanwenxuan/archive/2011/08/13/2137432.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.