做了一个修改密码页面,可运行后老是出现"connectionstring 属性尚未初始化",不知怎么回事,代码看了好几遍也不知问题在哪里...
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["DBConnecton"]);
        SqlCommand selectcmd = new SqlCommand("select * from Users where userId='" + Session["userId"].ToString() + "'and userPwd='" + txtOldPwd.Text.Trim() + "'", conn);
        try
        {
            conn.Open();
            SqlDataReader sdr = selectcmd.ExecuteReader();
            if (sdr.Read())
            {
                sdr.Close();
                SqlCommand updatecmd = new SqlCommand("update Users set userPwd='" + txtNewPwd.Text.Trim() + "' where userId='" + Session["userId"].ToString() + "'", conn);
                int i = updatecmd.ExecuteNonQuery();
                if (i > 0)
                {
                    Response.Write("<script language=javascript>alert('成功修改密码!')</script>");
                }
                else
                {
                    Response.Write("<script language=javascript>alert('修改密码失败! ')</script>");
                }
            }
            else
            {
                Response.Write("<script language=javascript>alert('您输入的密码错误,检查后重新输入!')</script>");
            }
        }
        catch (System.Exception ee)
        {
            Response.Write("<script language=javascript>alert('" + ee.Message.ToString() + "')</script>");
        }
        finally
        {
            conn.Close();
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        this.txtOldPwd.Text = "";
        this.txtNewPwd.Text = "";
        this.txtConfirmPwd.Text = "";
    }
    protected void btnback_Click(object sender, EventArgs e)
    {
        Response.Redirect("Login.aspx");
    }
}

解决方案 »

  1.   

    SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["DBConnecton"]); 
    DBConnecton 这个KEY   WEBCONFIG里面有链接数据库吗
      

  2.   

    有啊,在web.config配置文件中已经写过了,可还是出这样提示,不知怎么修改.
      

  3.   

    SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["DBConnecton"].ToString());
    看一下是不是这样的。 
      

  4.   

    只有这个:SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["DBConnecton"];