Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

AdoQueryConnection.BuildSqlFromXmlNodes method

Returns a SQL command text fragment parsed from the specified XML node that contains query fields values.

Namespace:  Microsoft.Office.InfoPath
Assembly:  Microsoft.Office.InfoPath (in Microsoft.Office.InfoPath.dll)
PublicMustOverrideFunctionBuildSqlFromXmlNodes ( _
	inputAsXPathNavigator _
) AsString
DiminstanceAsAdoQueryConnectionDiminputAsXPathNavigatorDimreturnValueAsStringreturnValue = instance.BuildSqlFromXmlNodes(input)


Type: System.Xml.XPath.XPathNavigator

An XPathNavigator that is positioned at the dfs:queryFields XML node that contains the query field values to be converted to an SQL fragment.

Return value

Type: System.String
A WHERE clause built from the query fields values in the specified node.

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 query field values.

  • The input node contains columns (XML attributes) that are not present in the data source that is being queried.


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


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 fieldname = value pairs. If there are more than one pair, each pair is combined with the AND operator. 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')

The XML node that you specify for the input parameter must be a descendant of the dfs:queryFields node of the form. You can add the SQL command text fragment to the existing SQL command string of the ADOQueryConnection object using the Command property.


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 from code running in forms opened in Microsoft InfoPath Filler or in a Web browser.

In the following example, the event handler for a Button control uses the BuildSQLFromXMLNodes method of the ADOQueryConnection 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 named "Main connection" to the Employees table in the SQL Server Northwind sample database.

Public Sub DisplaySQL_Clicked(ByVal sender As Object, _
   ByVal e As ClickedEventArgs)
   ' Get the query fields node.
   Dim queryFieldsXPath As String = 
   Dim mainDataSourceNav As XPathNavigator  = _
   Dim queryFieldsNav As XPathNavigator = _
      mainDataSourceNav.SelectSingleNode( _
      queryFieldsXPath, NamespaceManager)

   ' Create AdoQueryConnection from the 
   ' DataConnections collection.
   Dim myAdoQueryConnection As AdoQueryConnection  = _
      DirectCast(DataConnections["Main connection"], _
   ' Display BuildSQLFromXMLNodes output.
   Dim sqlFromXmlNodes As String  = 
End Sub
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.