Write an sql result inside a Textbox in infopath - InfoPath Dev
in

InfoPath Dev

Write an sql result inside a Textbox in infopath

Last post 12-30-2015 08:30 AM by Hilary Stoupa. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 12-23-2015 06:32 AM

    Write an sql result inside a Textbox in infopath

    OBS: Im sorry, i dont know how to format code on this website, it seems to be normal when i type it in here but not when it's posted Hi I have 2 textfields: Textfield 1 - the user types an input number Textfield 2 - You get the result from what the user typed in the first textfield. public void Btn_Check_Clicked(object sender, ClickedEventArgs e) { XPathNavigator elemYourTextBox1 = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:Txb_1", this.NamespaceManager); String DataFromTextField = elemYourTextBox1.Value; XPathNavigator elemYourTextBox2 = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:Txb_2", this.NamespaceManager); String DataFromTextField_Result = elemYourTextBox2.Value; //My query string AdoQueryConnection conn = (AdoQueryConnection)(this.DataConnections["DBConnection"]); string sql = "Select Distinct Name from TableUsers where ID = '" + DataFromTextField + "'"; conn.Command = sql; conn.Execute(); //Here i want my result viewed once the button is clicked DataFromTextField_Result = Name (the result from my sql query) } My problem is I don't know how to make my sql query get the result and view it on my textfield, infopath makes it really hard for me to do clean C# code in the codebehind part
  • 12-30-2015 08:30 AM In reply to

    Re: Write an sql result inside a Textbox in infopath

     You just need to get the value for the Name field from your secondary data connection (looks like the name is "DBConnection"?) and set the value of the field you want to have the result in.

    So, you need the XPath to the field in the secondary data connection (right click on it in the Fields task pane in InfoPath and select "copy XPath"), then get the value of it:


    XPathNavigator nameField = this.DataSources["DBConnection"].CreateNavigator().SelectSingleNode("YourXPathHere", NamespaceManager);
    if (null != nameField)
    {
         elemYourTextBox2.SetValue(nameField.Value);
    }

    Hilary Stoupa

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