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