修改密码的问题
我是直接取保存在sql数据库表中的数据
protected void Button1_Click(object sender, EventArgs e)
{
string strSqlCustompass = "select password from users where userid = ' "+ LabelCustomID + " ' ";
string aa = TextBox1.Text;
if (aa != Session[ "custompass "].ToString())
{
Label1.Text = "初始密码输入错误 ";
}
else
{
...
}
}
结果if (aa != Session[ "custompass "].ToString())提示错误:
未将对象引用设置到对象的实例。
应该怎么改?
还有else下面,该如何调用SQL的UPDATE语句?
------解决方案--------------------是不是Session里就没有保存custompass?
------解决方案-------------------- <1>
未将对象引用设置到对象的实例-----
应该是因为你的Session没有值
if (Session[ "custompass "]!=null && aa != Session[ "custompass "].ToString())
{...}
<2>
Update user
set LabelCustomID = test1.text
where custompass = strSqlCustompass(你上面查询到的LabelCustomID字段的值)
------解决方案--------------------string strSqlCustompass = "select password from users where userid = ' " + LabelCustomID + " ' ";
string aa = TextBox1.Text;
string ConnStr = "... ";
SqlConnection conn = new SqlConnection(ConnStr);
SqlCommand cmd = new SqlCommand(strSqlCustompass, conn);
try
{
conn.Open();
object obj = cmd.ExecuteScalar();
if (obj == null)
{
//出错
}
if (aa != obj.ToString())
{
Label1.Text = "初始密码输入错误 ";
}
else
{
//
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
------解决方案--------------------TO:对了 数据库连接我已经做在web.config里面了,那么
string ConnStr = "... ";
SqlConnection conn = new SqlConnection(ConnStr);
这一步怎么处理呢?
读配置文件,连接字符串取出即可...
------解决方案--------------------C#里用
MessageBox.Show(ex.Message);
VB用多了吧!