ADOAdapter2.BuildSQLFromXMLNodes(IXMLDOMNode) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a SQL command text fragment using the specified XML node.
public:
System::String ^ BuildSQLFromXMLNodes(Microsoft::Office::Interop::InfoPath::Xml::IXMLDOMNode ^ pXmlNode);
public string BuildSQLFromXMLNodes (Microsoft.Office.Interop.InfoPath.Xml.IXMLDOMNode pXmlNode);
abstract member BuildSQLFromXMLNodes : Microsoft.Office.Interop.InfoPath.Xml.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 '>=', and append the clause to
// the SQL command text.
whereClause = whereClause.Replace(@"=", @">=");
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.