AdoSubmitConnection.BuildSqlFromXmlNodes Method (Microsoft.Office.InfoPath)
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
- input
An XPathNavigator object that specifies the XML node to be converted to an SQL fragment.
Return Value
The WHERE clause for the specified node.
Exceptions
Exception type | Condition |
---|---|
One of the following conditions has occurred:
|
|
The parameter passed to this method is null. |
|
The parameter passed to this method isnot 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 Office InfoPath 2007.
Example
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