AdoSubmitConnection.BuildSqlFromXmlNodes Method

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

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

Syntax

'Declaration
Public MustOverride Function BuildSqlFromXmlNodes ( _
    input As XPathNavigator _
) As String
'Usage
Dim instance As AdoSubmitConnection
Dim input As XPathNavigator
Dim returnValue As String

returnValue = instance.BuildSqlFromXmlNodes(input)
public abstract string BuildSqlFromXmlNodes(
    XPathNavigator input
)

Parameters

Return Value

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

Exceptions

Exception Condition
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.

Remarks

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.

Note

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.

Examples

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);
}
Public Sub DisplaySQL_Clicked(ByVal sender As Object, _
   ByVal e As ClickedEventArgs)
   ' Get the query fields node.
   Dim queryFieldsXPath As String = 
      "dfs:myFields/dfs:queryFields/q:Employees"
   Dim mainDataSourceNav As XPathNavigator  = _
      MainDataSource.CreateNavigator()
   Dim queryFieldsNav As XPathNavigator = _
      mainDataSourceNav.SelectSingleNode( _
      queryFieldsXPath, NamespaceManager)

   ' Create AdoSubmitConnection from the 
   ' DataConnections collection.
   Dim myAdoSubmitConnection As AdoSubmitConnection  = _
      DirectCast(DataConnections["Main connection submit"], _
      AdoSubmitConnection)
   
   ' Display BuildSQLFromXMLNodes output.
   Dim sqlFromXmlNodes As String  = 
      myAdoSubmitConnection.BuildSqlFromXmlNodes(queryFieldsNav)
   MessageBox.Show(sqlFromXmlNodes)
End Sub

See Also

Reference

AdoSubmitConnection Class

AdoSubmitConnection Members

Microsoft.Office.InfoPath Namespace