异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
行 57:         myCommand.Parameters["@Contract"].Value = contract.Value;
行 58: 
行 59:         myCommand.Connection.Open();
行 60: 
行 61:         try 
 源文件: c:\inetpub\wwwroot\webform\WebForm4.aspx    行: 59 堆栈跟踪: 
[NullReferenceException: 未将对象引用设置到对象的实例。]
   ASP.WebForm4_aspx.AddAuthor_Click(Object sender, EventArgs E) in c:\inetpub\wwwroot\webform\WebForm4.aspx:59
   System.Web.UI.HtmlControls.HtmlInputButton.OnServerClick(EventArgs e)
   System.Web.UI.HtmlControls.HtmlInputButton.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() 
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.2032; ASP.NET 版本:1.1.4322.2032 
------------------------------------------

解决方案 »

  1.   

    其实造成这一原因可能是因为你的链接串出现问题,你将
    user id=sa直接改成user=sa试试!
      

  2.   

    myConnection=new SqlConnection("server=localhost;Initial catalog=pubs;user id=sa;password=;");
    放到 public void AddAuthor_Click(Object sender, EventArgs E) 
      

  3.   

    异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。出现这种信息通常是由于对象为实例化,或者为空造成的。行 57:         myCommand.Parameters["@Contract"].Value = contract.Value;
    行 58: 
    行 59:         myCommand.Connection.Open();
    行 60: 
    行 61:         try 可能是由于contract为空造成的。你设个断点,单步调试一下。
      

  4.   

    你必须要为myCommand.Connection 赋值才行:myCommand.Connection =new OleConnection("你的连接字符串");
    ...
    myCommand.Connection.Open();
      

  5.   

    加入myConnection=new SqlConnection("server=localhost;Initial catalog=pubs;user id=sa;password=;");
    myCommand.Connection=myConnection;