Retrieving and populating a form value from a SELECT statement - InfoPath Dev
in

InfoPath Dev

Retrieving and populating a form value from a SELECT statement

Last post 09-24-2013 07:19 PM by aebailey40. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 09-18-2013 08:09 AM

    Retrieving and populating a form value from a SELECT statement

     Hello-

     I have been trying to get a form to use a data connection and execute a SELECT statement to get a value, then put that value on a form. I know this isn't difficult but I cannot see what I am missing. Here is my code - I think it is pretty self explanatory:

     

    public void CTRL645_5_Clicked(object sender, ClickedEventArgs e)

    {

     

    XPathNavigator MDMid = CreateNavigator().SelectSingleNode("/my:myFields/my:sectCommon/my:MDMid", NamespaceManager);

    XPathNavigator custName = CreateNavigator().SelectSingleNode("/my:myFields/my:sectCommon/my:custName", NamespaceManager);

    XPathNavigator RetCustName = CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:DAL_PARTY/@CUST_NAME", NamespaceManager);

    string MDMidNum = MDMid.InnerXml;

    AdoQueryConnection myAdoQueryConnection = (AdoQueryConnection)(this.DataConnections["DAL_PARTY"]);

    myAdoQueryConnection.Command = "select CUST_NAME from [DAL_PARTY] where [ROWID_OBJECT] = " + MDMidNum;

     

    myAdoQueryConnection.Execute();

     

    custName.SetValue(RetCustName.Value);

     

    }

    I am receiving a null object exception on the last line, but I copied the XPath and pasted it. What could I be missing? I know the data is there...

     

    Thanks in advance,

    -Drew

  • 09-24-2013 05:58 PM In reply to

    Re: Retrieving and populating a form value from a SELECT statement

     Well - I'd expect you'd need to create a navigator for the secondary data source - I usually use MainDataSource.CreateNavigator() for main data source nodes and this.DataSources["DataSourceNameGoesHere"].CreateNavigator() for secondary data sources....

    Hilary Stoupa

  • 09-24-2013 07:19 PM In reply to

    Re: Retrieving and populating a form value from a SELECT statement

     Thanks Hilary - you're exactly right! I followed it to a namespace error and that got me thinking along those lines. I'll post the working code here in case it can be of help to anyone else in the future.

     Thanks again!

    -Drew 

    public void CTRL645_5_Clicked(object sender, ClickedEventArgs e)

     

    {

     

    XPathNavigator MDMid = CreateNavigator().SelectSingleNode("/my:myFields/my:sectCommon/my:MDMid", NamespaceManager);

    XPathNavigator custName = CreateNavigator().SelectSingleNode("/my:myFields/my:sectCommon/my:custName", NamespaceManager);

     

     

    string MDMidNum = MDMid.InnerXml;

    AdoQueryConnection myAdoQueryConnection = (AdoQueryConnection)(this.DataConnections["DAL_PARTY"]);

    myAdoQueryConnection.Command = "select CUST_NAME from [DAL_PARTY] where [ROWID_OBJECT] = " + MDMidNum;

     

     

    myAdoQueryConnection.Execute();

     

    XPathNavigator RetCustName = this.DataSources["DAL_PARTY"].CreateNavigator();

    XPathNavigator ReturnedCustName = RetCustName.SelectSingleNode("//dfs:myFields/dfs:dataFields/d:DAL_PARTY/@CUST_NAME", NamespaceManager);

     

     

    custName.SetValue(ReturnedCustName.InnerXml);

     

    }

     

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.