Compartilhar via


ADOAdapter2.BuildSQLFromXMLNodes(IXMLDOMNode) Método

Definição

Retorna um fragmento de texto de comando SQL usando o nó XML especificado.

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

Parâmetros

pXmlNode
IXMLDOMNode

O nó XML a ser convertido em um fragmento SQL.

Retornos

Um fragmento de texto de comando SQL.

Implementações

Exemplos

No exemplo a seguir, o método BuildSQLFromXMLNodes é usado para consultar a tabela Orders do banco de dados Northwind. Os dados retornados são filtrados para itens maiores ou iguais ao valor do 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;
}

Comentários

O fragmento de SQL que o método BuildSQLFromXMLNodes gera é uma cláusula SQL WHERE na forma de campo = valor. O nó XML que você usa para o pXmlNode argumento deve ser um descendente do nó; quando você tiver o fragmento de dfs:queryFields texto de comando SQL, você pode adicioná-lo à cadeia de comando SQL existente do ADOAdapterObject objeto usando a Command propriedade.

Aplica-se a