问候,
我有一个InfoPath 2007表单,其中部分表单(主要是更改的事件)的编程是在C#中完成的。我试图将这些转换为VB,但是,我遇到了DataConnection.Execute()的问题
下面看到的原始C#代码:
XPathNavigator main = MainDataSource.CreateNavigator();
XPathNavigator mainStart = main.SelectSingleNode("*xPath*", NamespaceManager);
string strWO = mainStart.Value.ToString();
DataSource ds = DataSources["Discrepancies"];
XPathNavigator xnds = ds.CreateNavigator();
xnds.SelectSingleNode("*xPath*", NamespaceManager).SetValue(strWO);
DataConnection dc = ds.QueryConnection;
dc.Execute();
XPathNavigator nvgFaults = DataSources["Discrepancies"].CreateNavigator();
XPathNodeIterator faultNodes = nvgFaults.Select("*xpath*", NamespaceManager);
while (faultNodes.MoveNext())
{
string nodeSequence = faultNodes.Current.SelectSingleNode("ACTION_SEQUENCE", NamespaceManager).Value;
string nodeFault = faultNodes.Current.SelectSingleNode("FAULT_NOTES", NamespaceManager).Value;
string nodeAction = faultNodes.Current.SelectSingleNode("ACTION_NOTES", NamespaceManager).Value;
writer.WriteStartElement("group4", myNameSpace);
writer.WriteElementString("txtSequence", myNameSpace, nodeSequence);
writer.WriteElementString("txtFault", myNameSpace, nodeFault);
writer.WriteElementString("txtAction", myNameSpace, nodeAction);
writer.WriteEndElement();
}
正确执行,按预期填写我的表单,但是,如下所示的VB代码不会:
Dim main As XPathNavigator = MainDataSource.CreateNavigator()
Dim mainStart As XPathNavigator = main.SelectSingleNode("*xPath*", NamespaceManager)
Dim strWO As String = mainStart.Value.ToString
Dim dsresult As DataSource = DataSources("Discrepancies")
Dim xNav As XPathNavigator = dsresult.CreateNavigator()
xNav.SelectSingleNode("*xPath*", NamespaceManager).SetValue(strWO)
Dim dataConn As DataConnection = dsresult.QueryConnection()
dataConn.Execute()
Dim navFaults As XPathNavigator = DataSources("Discrepancies").CreateNavigator()
Dim faultNodes As XPathNodeIterator = navFaults.Select("*xPath*", NamespaceManager)
Dim myNameSpace As String = NamespaceManager.LookupNamespace("my")
While faultNodes.MoveNext()
Dim nodeSequence As String = faultNodes.Current.SelectSingleNode("ACTION_SEQUENCE", NamespaceManager).Value
Dim nodeFault As String = faultNodes.Current.SelectSingleNode("FAULT_NOTES", NamespaceManager).Value
Dim nodeAction As String = faultNodes.Current.SelectSingleNode("ACTION_NOTES", NamespaceManager).Value
Using writer As XmlWriter = MainDataSource.CreateNavigator(). _
SelectSingleNode("/my:myFields/my:group1", NamespaceManager).AppendChild()
writer.WriteStartElement("group2", myNameSpace)
writer.WriteElementString("txtSequence", myNameSpace, nodeSequence)
writer.WriteElementString("txtFault", myNameSpace, nodeFault)
writer.WriteElementString("txtAction", myNameSpace, nodeAction)
writer.WriteEndElement()
writer.Close()
End Using
End While
我已经运行了几个测试(在示例中没有说明)来证明我实际上正在获取正确的变量,例如'strWO'。然后将此变量传递给DataSource“Discrepancies”,这是一个存储过程。
如果我通过我的WebMethod调用SP差异(也转换为VB),它确实会返回它应该的信息。这一切都很好。我得到了我期望的信息。
但是,VB版本不执行查询。对节点计数进行简单测试,得到'0'虽然我正在测试的特定项目应该返回低40的节点数。有数据,但我无法执行查询。这让我很生气。
一些变量名称不同于c#到vb,以及一些infoPath xPaths,为了便于阅读,我将其简化为 xpath 。其中一些xPaths很长。但是,我很肯定任何变量名称更改都是一致的。
感谢任何帮助。
感谢。