Use vsta to dynamically change the infopath Data Source Query parameters and reverse query results

Source: Internet
Author: User

It is very convenient to use infopath to reference external data sources and perform data operations, such as connecting to the SQL database and referencing WebServices, XML, and Sharepoint list. However, we found a problem, when infopath references a data source, the data is cached on the client. When the referenced data source is large, the user operation is slow. At this time, we hope that the downloaded data can be small and accurate. We can customize the data source and add parameters to achieve dynamic data source query. In vsta, You can dynamically change the data source query parameters and reverse query results by referring to the following code:

 

Code

Public void ctrl1_14_clicked (Object sender, clickedeventargs E)
{
// Write code here.
System. xml. XPath. xpathnavigator root;
Root = This. maindatasource. createnavigator ();
Dataconnection Dc = (dataconnection) datasources ["getdata"]. queryconnection); // obtain the data source object

If (DC is webserviceconnection)
{
String queryfield = ""
+ "<TNS: getdata xmlns: TNS = \" http://tempuri.org/\ "> <TNS: secucode>" + root. selectsinglenode ("// NS2. securities code", this. namespacemanager ). value + "</TNS: secucode>"

+ "<TNS: tradingday>" + root. selectsinglenode ("// NS2. query date", this. namespacemanager). Value + "</TNS: tradingday>"
+ "</TNS: getdata>"
+ "";
Xmldocument inputdocument = new xmldocument ();
Inputdocument. loadxml (queryfield );
Xpathnavigator inputnav = inputdocument. createnavigator ();

Xmldocument outputdocument = new xmldocument ();
Xpathnavigator outputnav = outputdocument. createnavigator ();

Microsoft. Office. infopath. webserviceconnection fqc = (Microsoft. Office. infopath. webserviceconnection) DC;

Fqc. Execute (inputnav, outputnav, null); // execute Data Query
// MessageBox. Show (outputnav. outerxml );

String outxml = outputnav. outerxml. Replace ("xmlns = \" http://tempuri.org /\"","");
Outputdocument. loadxml (outxml );

Xmlelement nodeelement = (xmlelement) outputdocument. selectsinglenode ("getdataresponse/getdataresult/securities abbreviation ");
Xpathnavigator setnode = root. selectsinglenode ("// NS2. company name", this. namespacemanager );
Deletenil (setnode );
Setnode. setvalue (nodeelement. innertext); // attaches a value to the infopath Field

Nodeelement = (xmlelement) outputdocument. selectsinglenode ("getdataresponse/getdataresult/transaction date ");
Setnode = root. selectsinglenode ("// NS2. Transaction date", this. namespacemanager );
Deletenil (setnode );
Setnode. setvalue (nodeelement. innertext );

}
}
Public void deletenil (xpathnavigator node)
{
If (node. movetoattribute (
"Nil", "http://www.w3.org/2001/XMLSchema-instance "))
Node. deleteself ();
}

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.