


























用infopath 引用外部数据源,进行数据操作,是一件非常方便的事情,比如连接SQL数据库,引用webServices、xml、sharepoint list等,但是我们发现了一个问题,infopath引用数据源时,会将数据缓存在客户端,当我们引用的数居源数据量大的时候,会产生用户操作缓慢的问题。这个时候我们希望下载下来数据能够,既小又准确。我们能够通过自定义数据源加参数的方法,实现动态的数据源查询。在VSTA中动态改变数据源查询参数与反回查询结果,可以参考如下代码:
代码
public void CTRL1_14_Clicked(object sender, ClickedEventArgs e)
{
// 在此处编写代码。
System.Xml.XPath.XPathNavigator root;
root = this.MainDataSource.CreateNavigator();
DataConnection dc = ((DataConnection)DataSources["GetData"].QueryConnection);//获取数据源对象if (dc is WebServiceConnection)
{
string queryField = ""
+ "<tns:GetData xmlns:tns=\"http://tempuri.org/\"><tns:SecuCode>" + root.SelectSingleNode("//ns2:证券代码", this.NamespaceManager).Value + "</tns:SecuCode>"
+ " <tns:TradingDay>" + root.SelectSingleNode("//ns2:查询日期", this.NamespaceManager).Value + "</tns:TradingDay>"
+ " </tns:GetData>"
+ "";
XmlDocument inputDocument=new XmlDocument();
inputDocument.LoadXml(queryField);
XPathNavigator inputNav= inputDocument.CreateNavigator();
XmlDocument outputDocument
= new XmlDocument();Microsoft.Office.InfoPath.WebServiceConnection fqc
= (Microsoft.Office.InfoPath.WebServiceConnection)dc;fqc.Execute(inputNav, outputNav,
null);//执行数据查询XmlElement nodeElement
= (XmlElement)outputDocument.SelectSingleNode("GetDataResponse/GetDataResult/证券简称");nodeElement
= (XmlElement)outputDocument.SelectSingleNode("GetDataResponse/GetDataResult/交易日期"); }
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。