异常详细信息: 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
------------------------------------------
行 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
------------------------------------------
user id=sa直接改成user=sa试试!
放到 public void AddAuthor_Click(Object sender, EventArgs E)
中
行 58:
行 59: myCommand.Connection.Open();
行 60:
行 61: try 可能是由于contract为空造成的。你设个断点,单步调试一下。
...
myCommand.Connection.Open();
myCommand.Connection=myConnection;