I am trying to do something similar to this click here - utilizing secondary datasource in InfoPath, however in C#. I found another article that connect the secondary data source to a webservice - quite helpful but I still couldn't get around to making it work properly.
// Get a reference to the secondardy datasource
IXMLDOMDocument2 spDOM = (IXMLDOMDocument2)thisXDocument.DataObjects["Contact Details"].DOM;
// Set the SelectionNamspaces to find the correct fields
spDOM.setProperty("SelectionNamespaces", "xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\"");
// Get the selected contact text
string selectedContact = thisXDocument.DOM.selectSingleNode("/my:document/my:metadata/my:doc_contact_name").text;
// Get the selected node
spDOM.selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Contact_Details[@Name='" + selectedContact + "']");
// Set the texbox texts
thisXDocument.DOM.selectSingleNode("/my:document/my:metadata/my:doc_contact_role").text = spDOM.documentElement.attributes.getNamedItem("Title").text;
Just wondering if anyone could point out what I'm doing wrong. The error: Object reference not set to an instance of an object
Thanks in advance.