Edit

Share via


ADOAdapter2.BuildSQLFromXMLNodes(IXMLDOMNode) Method

Definition

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

public:
 System::String ^ BuildSQLFromXMLNodes(Microsoft::Office::Interop::InfoPath::SemiTrust::IXMLDOMNode ^ pXmlNode);
public string BuildSQLFromXMLNodes (Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode pXmlNode);
abstract member BuildSQLFromXMLNodes : Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode -> string
Public Function BuildSQLFromXMLNodes (pXmlNode As IXMLDOMNode) As String

Parameters

pXmlNode
IXMLDOMNode

The XML node to be converted to an SQL fragment.

Returns

A SQL command text fragment.

Implements

Examples

In the following example, the BuildSQLFromXMLNodes method is used to query the Orders table of the Northwind database. The data returned is filtered for items greater than or equal to the value of the queryFieldNode:

private void QueryGreaterThan()
{
 string oldCommand;
 string whereClause;
 IXMLDOMNode queryFieldNode;
 IXMLDOMNode curQueryFieldAttribute;
 IXMLDOMNamedNodeMap queryFieldAttributes;
 ADOAdapter adapter = (ADOAdapter)thisXDocument.QueryAdapter;

 // Build the WHERE clause from the QueryFields in the form's
 // underlying XML DOM.
 queryFieldNode = thisXDocument.DOM.selectSingleNode("dfs:myFields/dfs:queryFields/q:Orders");
 whereClause = adapter.<span class="label">BuildSQLFromXMLNodes</span>(queryFieldNode);

// The QueryFields are empty.
 if (whereClause == null)
 {
  whereClause = String.Empty;
 }
 // Replace the '=' signs with '&gt;=', and append the clause to 
 // the SQL command text.
 whereClause = whereClause.Replace(@"=", @"&gt;=");
 oldCommand = adapter.Command;

 if (whereClause != "")
 {
  adapter.Command = oldCommand + " where " + whereClause;
 }

 // Clear the QueryFields so the WHERE clause isn't 
 // automatically generated.
 queryFieldAttributes = queryFieldNode.attributes;
 while ((curQueryFieldAttribute = queryFieldAttributes.nextNode()) != null)
 {
  curQueryFieldAttribute.text = "";
 }

  // Perform the query.
 try
 {
  thisXDocument.Query();
 }
 catch (Exception ex)
 {
  thisXDocument.UI.Alert("Failed to query.\n\n" + ex.Message);
 }

 // Reset the command so that subsequent queries are based on 
 // the correct SQL command text string.
 adapter.Command = oldCommand;
}

Remarks

The fragment of SQL that the BuildSQLFromXMLNodes method generates is an SQL WHERE clause in the form of field = value. The XML node that you use for the pXmlNode argument should be a descendant of the dfs:queryFields node; when you have the SQL command text fragment, you can add it to the existing SQL command string of the ADOAdapterObject object using the Command property.

Important: 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.

Applies to