BuildSqlFromXmlNodes method
Collapse the table of content
Expand the table of content

AdoSubmitConnection.BuildSqlFromXmlNodes method

Office 2013 and later

Returns a SQL command text fragment using the specified XML node.

Namespace:  Microsoft.Office.InfoPath
Assembly:  Microsoft.Office.InfoPath (in Microsoft.Office.InfoPath.dll)

public abstract string BuildSqlFromXmlNodes(
	XPathNavigator input
)

Parameters

input
Type: System.Xml.XPath.XPathNavigator

An XPathNavigator object that specifies the XML node to be converted to an SQL fragment.

Return value

Type: System.String
The WHERE clause for the specified node.

ExceptionCondition
InvalidOperationException

One of the following conditions has occurred:

  • The SQL command string generated from the input node cannot be parsed.

  • The input node is not a table of values.

  • The input node contains columns (XML attributes) that are not present in the data source to which they are being submitted.

ArgumentNullException

The parameter passed to this method is a null reference (Nothing in Visual Basic).

ArgumentException

The parameter passed to this method is not valid. For example, it is of the wrong type or format.

The fragment of SQL that the BuildSQLFromXMLNodes method generates is an SQL WHERE clause in the form of field = value pairs. The XML node that you specify for the input parameter must be a descendant of the dfs:queryFields node of the form. For example, if the user queried the Employees table of the Northwind database by entering Davolio and Nancy in the query fields for the Last Name and First Name fields, the SQL fragment returned by the BuildSQLFromXmlNode method would be:

("Employees"."LastName"='Davolio' AND "Employees"."FirstName"='Nancy')

You can add the SQL command text fragment to the existing SQL command string of the ADOSubmitConnection object using the Command property.

NoteNote

To determine the XPath expression for the table that contains the query field values to pass for the input parameter, display the Data Source task pane, expand the queryFields group, right-click the table that contains the query fields you want to work with, and then click Copy XPath.

This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

This type or member can be accessed only from code running in forms opened in Microsoft InfoPath Filler.

In the following example, the event handler for a Button control uses the BuildSQLFromXMLNodes method of the AdoSubmitConnection class to parse the current query field values and display them in a message box.

This example assumes that the form template has a data connection for submitting data named "Main connection submit" to the Employees table in the SQL Server Northwind sample database.

public void DisplaySQL_Clicked(object sender, ClickedEventArgs e)
{
   // Get the query fields node.
   string queryFieldsXPath = 
      "dfs:myFields/dfs:queryFields/q:Employees";
   XPathNavigator mainDataSourceNav = MainDataSource.CreateNavigator();
   XPathNavigator queryFieldsNav = mainDataSourceNav.SelectSingleNode(
      queryFieldsXPath, NamespaceManager);

   // Create AdoSubmitConnection from the 
   // DataConnections collection.
   AdoSubmitConnection myAdoSubmitConnection = 
      (AdoSubmitConnection)(DataConnections["Main connection submit"]);
   
   // Display BuildSQLFromXMLNodes output.
   string sqlFromXmlNodes = 
      myAdoSubmitConnection.BuildSqlFromXmlNodes(queryFieldsNav);
   MessageBox.Show(sqlFromXmlNodes);
}
Show:
© 2016 Microsoft