我是 asp.net 的新手,我正在编写一个用于学习 asp.net 的登录页面,这是脚本的错误。当我输入密码只包含英文字母时,没有错误,但是当我输入密码包含数字/只有数字时,例如 abc123 或 123,第 28 行会产生错误,有人知道是什么问题吗?
谢谢
Object reference not set to an instance of an object.
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 26: string cmdStr2 = "Select Password from [user] where UserName = '" + TextBox2.Text + "'";
Line 27: SqlCommand pass = new SqlCommand(cmdStr2, con);
Line 28: string password = pass.ExecuteScalar().ToString();
Line 29:
Line 30: Label1.Text = password;
Source File: c:\inetpub\web1\Login.aspx.cs Line: 28
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Login.Button1_Click(Object sender, EventArgs e) in c:\inetpub\web1\Login.aspx.cs:28
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563