ADOAdapter2.BuildSQLFromXMLNodes(IXMLDOMNode) 方法

定义

返回一个使用指定 XML 节点的 SQL 命令文本片段。

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

参数

pXmlNode
IXMLDOMNode

要转换为 SQL 片段的 XML 节点。

返回

SQL 命令文本片段。

实现

示例

在以下示例中,BuildSQLFromXMLNodes 方法用于查询 Northwind 数据库的“定单”表。 根据大于或等于 的值 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;
}

注解

BuildSQLFromXMLNodes 方法所生成的 SQL 片段是形式为 field = value 的 SQL WHERE 子句。 用于 参数的 pXmlNode XML 节点应是节点的dfs:queryFields后代;如果具有 SQL 命令文本片段,则可以使用 Command 属性将其添加到对象的现有 SQL 命令字符串ADOAdapterObject中。

重要提示:此成员只能由与当前打开的窗体在同一域中运行的表单访问,或者由已授予跨域权限的表单访问。

适用于