# BuildSQLFromXMLNodes Method

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

expression.BuildSQLFromXMLNodes(ByRef pXmlNode As IXMLDOMNode) As String

expression Required. An expression that returns a reference to the ADOAdapter object.

pXmlNode Required Object. The XML node to be converted to an SQL fragment.

returns String.

## Security Level

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

## 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 ADOAdapter object using the Command property.

## Example

In the following example, the BuildSQLFromXMLNodes method of the ADOAdapter object is used to create an SQL command text fragment based on a specified XML node. This example is based on a form that uses the Orders table in the Microsoft SQL Server Northwind sample database.

    function QueryGreaterThan()
    {
       var objQueryFieldNode;
       var strWhereClause;
       var strOldCommand;
       var objQueryFieldAttributes;
       var objCurQueryFieldAttribute;

       // Build the WHERE clause from the QueryFields in the form's
       // underlying XML DOM.
       objQueryFieldNode = XDocument.DOM
          .selectSingleNode("dfs:myFields/dfs:queryFields/q:Orders");
       strWhereClause = XDocument.QueryAdapter
          .BuildSQLFromXMLNodes(objQueryFieldNode);

       // Replace the '=' signs with '>=', and append the clause to
       // the SQL command text.
       strWhereClause = strWhereClause.replace(/=/, ">=");
       strOldCommand = XDocument.QueryAdapter.Command;

       if (strWhereClause != "")
       {
          XDocument.QueryAdapter.Command = strOldCommand +
             " where " + strWhereClause;
       }

       // Clear the QueryFields so the WHERE clause isn't
       // automatically generated.
       objQueryFieldAttributes = objQueryFieldNode.attributes;
       while (objCurQueryFieldAttribute = objQueryFieldAttributes.nextNode())
       {
          objCurQueryFieldAttribute.text = "";
       }

       // Perform the query.
       try
       {
          XDocument.Query();
       }
       catch (e)
       {
          XDocument.UI.Alert("Failed to query.\n\n" + e.message);
       }

       // Reset the command so that subsequent queries are based on
       // the correct SQL command text string.
       XDocument.QueryAdapter.Command = strOldCommand;

       // Clean up.
       objQueryFieldNode = null;
       strWhereClause = null;
       strOldCommand = null;
       objQueryFieldAttributes = null;
       objCurQueryFieldAttribute = null;

    }

©2003-2004 Microsoft Corporation. All rights reserved. Permission to copy, display and distribute this document is available at: http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp