How do you set a C# variable from an SQL query - InfoPath Dev
in

InfoPath Dev

How do you set a C# variable from an SQL query

Last post 12-01-2014 05:22 PM by HaydenLewin. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 11-30-2014 05:27 PM

    How do you set a C# variable from an SQL query

    I have a Form Load event that triggers ...

    Using a webservice I get the GUID of the active employee ...  I want to use this information to Query a table to get an "OID" for that user for use in further queries ..

      

    //Get the GUID of the current employee

    string strGUID = xnMain.SelectSingleNode("/my:myFields/my:GUID", ns).Value;

    //Declaure the strOID;

    string strOID = null;

     

    //Execute query to get the OID of the User; 

    AdoQueryConnection dsSQL = (AdoQueryConnection)this.DataConnections["GetOID"];

    string strOrigSQL = dsSQL.Command;

    dsSQL.Command = "select oid from odb3.vwPersonInfo where employeeguid = '" + strGUID + "';";

    dsSQL.Execute();

     

     

    //Need magic code here; 

    I need the code that allows me to set strOID = the returned value of the SQL Query

     

    Can anyone help me out? 

     

     

  • 12-01-2014 11:34 AM In reply to

    Re: How do you set a C# variable from an SQL query

    Hi!

    Since you are using a data connection in your form for this, you won't need too much magic, only a little.

    You'll need the XPath to the field in the data connection that will have the value - does that field show in the data source task pane?

    To get data from your secondary data connection:

    this.DataSources["GetOID"].CreateNavigator().SelectSingleNode("XPATHGOESHERE", NamespaceManager).Value;

    Hilary Stoupa

  • 12-01-2014 05:22 PM In reply to

    Re: How do you set a C# variable from an SQL query

    Thanks for the reply .. I did as you said but struck another problem. The SQL references a view and the XPath referenced the same view.

    However, that continually threw up a Null exception ...

     the xpath from InfoPath for the field is

    /dfs:myFields/dfs:dataFields/d:vwPersonInfo/@MyOid

     however, after a bit of hair pulling we realised that the SelectSingleNode didn't cope with a view and wanted a table, so we had to reference the original table 

    /dfs:myFields/dfs:dataFields/d:tbEmployee/@MyOid 

     

    All good now the form is working as it should 

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