找高人 关于用C# 编程 !@!!!!!!!!!!!!!!!!!!!!!
我用的是这个 API 函数 public virtual new void NtAccountCreate ( System.String bstrDomain , System.String bstrUserLogin , System.String bstrPassword , System.String bstrUserComment , System.String bstrLocalGroup )
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using MSExchangeAcctLib;
namespace exchangetest
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
public MSExchangeAcctLib.IAcctMgmt sd;
private void Button1_Click(object sender, System.EventArgs e)
{
//sd.NtAccountDelete( "utpcb.com ", "py-wang ");
sd.NtAccountCreate( "域名 ", "管理员账号 ", "密码 ", "新加的用户 ", "所属的组 ");
TextBox1.Text= "nihao ";
}
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
我的目的很简单 就是按下BUTTON就能加入我写入的用户名和密码
环境是 WIN2000 2003.NET
我运行点BUTTON后出现以下错误
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 24: {
Line 25: //sd.NtAccountDelete( "utpcb.com ", "py-wang ");
Line 26: sd.NtAccountCreate( "yu ", "zhanhao ", "mima ", "yonghu ", "zixun ");
Line 27:
Line 28:
Source File: c:\inetpub\wwwroot\exchangetest\webform1.aspx.cs Line: 26
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
exchangetest.WebForm1.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\exchangetest\webform1.aspx.cs:26
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
MSExchangeAcctLib 这个类是从MS网站下的一个域的接口
如果是
sd没有实例化啊,是null
public MSExchangeAcctLib.IAcctMgmt sd;
你只有定义,并没有给它初始化,自然会报错了
怎麽例啊??
[解决办法]
没用过,帮UP
[解决办法]
没用过,帮UP
[解决办法]
sd.NtAccountCreate
这个在哪个类里实现的,就按哪个类实例化贝