Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
BuildSqlFromXmlNodes method
Collapse the table of content
Expand the table of content

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)

Public MustOverride Function BuildSqlFromXmlNodes ( _
	input As XPathNavigator _
) As String
Dim instance As AdoQueryConnection
Dim input As XPathNavigator
Dim returnValue As String

returnValue = 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
© 2015 Microsoft