读书人

代码解决方法

发布时间: 2013-06-19 10:26:40 作者: rapoo

代码
using Microsoft.Office.InfoPath;
using System;
using System.Windows.Forms;
using System.Xml;
using System.Xml.XPath;
using mshtml;
//using System.Xml.Linq;
//using Microsoft.Office.Interop.InfoPath;
using Microsoft.Office.Interop.InfoPath.SemiTrust;
namespace 模板6
{
// public class thisXDocument : XDocument
//{
//}
public partial class FormCode
{
// 启用浏览器功能的表单不支持成员变量。
// 请使用代码从 FormState 词典
// 写入和读取这些值,如下所示:
//
// private object _memberVariable
// {
// get
// {
// return FormState["_memberVariable"];
// }
// set
// {
// FormState["_memberVariable"] = value;
// }
// }

// 注意: 以下是 Microsoft Office InfoPath 所需的过程。
// 可以使用 Microsoft Office InfoPath 对其进行修改。
public void InternalStartup()
{
EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
//public interface XDocument;
//XDocument thisXdocument=
}

public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
// 在此处编写代码。
string oldCommand;
string whereClause;

XDocument thisXDocument = new XDocument();
IXMLDOMNode queryFieldNode;
IXMLDOMNode curQueryFieldAttribute;
IXMLDOMNamedNodeMap queryFieldAttributes;
ADOAdapter adapter = (ADOAdapter)thisXDocument.QueryAdapter;


//IXMLDOMNode queryStaffId;
queryFieldNode = thisXDocument.DOM.selectSingleNode("dfs:myFields/dfs:dataFields/q:leave");
//queryFieldNode = thisXDocument.DOM.selectSingleNode("dfs:myFields/dfs:queryFields/q:leave");
whereClause = adapter.BuildSQLFromXMLNodes(queryFieldNode);
if (whereClause == null)
{
whereClause = string.Empty;
}
oldCommand = adapter.Command;
if (whereClause != "")
{
adapter.Command = oldCommand + "where" + whereClause;

}
queryFieldAttributes = queryFieldNode.attributes;
while ((curQueryFieldAttribute = queryFieldAttributes.nextNode()) != null)
{
curQueryFieldAttribute.text = "";
}
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;
}
}
}
我写了代码,但是调试的时候提示错误1“Microsoft.Office.Interop.InfoPath.SemiTrust.XDocumentWrapper”不可访问,因为它受保护级别限制,怎么解决,郁闷。。。以前没接触过XML


[解决办法]
thisXDocument 不是New 出来的,它是当前InfoPath表单实例内置的:
http://msdn.microsoft.com/en-CA/library/aa948640(v=office.14).aspx

读书人网 >行业软件

热点推荐