在C#.Net中搜索数据库时出现问题

问题描述:

每当我运行程序时,我都会收到一条错误消息:对象引用未设置为对象的实例".

异常详细信息:
用户代码未处理

Whenever i run the program i get an error saying "Object reference not set to an instance of an object".

Exception details:

System.NullReferenceException was unhandled by user code
  Message="Object reference not set to an instance of an object."
  Source="App_Web_6mjqddex"
  StackTrace:
       at _Default.btnSubmit_Click(Object sender, EventArgs e) in d:\WebSite1\Forgot password.aspx.cs:line 30
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 




程式码:




program code :

 protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string status;
        string selectQuery = "select emp_password,status from dbo.LogIn where login_ID='" + eID.Text + "'"; //Error line
        DataSet ds = new DataSet();
        ds =searchId(selectQuery);
        status = ds.Tables["LogIn"].Columns["status"].ToString();
        if (status == "false")
        {
            lblmsg.Text = "Invalid login ID";
        }
     }
public SqlConnection GetConnection()
    {

        ConnectionString.Open();

        return ConnectionString;
    }
    public void CloseSqlConnection()
    {
        ConnectionString.Close();
    }

  
    public DataSet SearchId(string selectQuery)
    {
        SqlDataAdapter adp = new SqlDataAdapter(selectQuery, GetConnection());
        DataSet ds = new DataSet();
        adp.Fill(ds);
        CloseSqlConnection();
        return ds;
    }



告诉我该怎么办?



Tell me what should i do?

您将eID变量设置为一个值吗?

我会将eID值硬编码为您知道的东西,然后从那里去.
Is you eID variable set to a value?

I''d hardcode the eID value to something you know exists and go from there.