这段修改用户密码的代码:
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["DBConnectionString"]);
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();
}
}
我在其他的页面也是这么用的,可是为什么到这个页面就不行了呢?望高手指教!