日期:2014-05-18  浏览次数:20952 次

密码修改的实现
用C#2003做的,数据库是SQL Server 2000,现在我要实现对密码的修改,整个窗口是这样的,“输入原密码”,“输入新密码”,“确认新密码”,确认按键,我自己写的不行,我的数据库里对应的密码表是Psw,数据库是BSS,请详细写一下这部分的代码。
注:这应该是数据库更新的问题,请高手指点,给30分了

------解决方案--------------------
SqlConnection dbconn = new SqlConnection("System.Configuration.ConfigurationManager.AppSettings["strcon"]"));
System.Data.SqlClient.SqlCommand myCmd = new SqlCommand("update [psw] set password=@password",dbconn);
 myCmd.Parameters.Add("@content", OleDbType.VarWChar, 255).Value=this.text1(新密码的文本框id).text.trim();
int count = Convert.ToInt32(myCmd.ExecuteNonQuery());
if (count > 0)
{
Response.Write("<script language=javascript>alert('您已经投票成功!');location='index.aspx'</script>");
}
连接字符串在web.config里设置下!
核对两次密码相同与否,用系统给出的验证控件就可以,这里不写了!
希望对你有帮助!

------解决方案--------------------
应该已经知道用户的ID了,假设是UserId,那末:

SqlConnection conn = new SqlConnection("server=.;database=BSS;integrated security=sspi");
SqlCommand cmd = new SqlCommand("select Password from PWS where UserId = "+UserId.ToString(),conn);

conn.Open();
string pwd = (string) cmd.ExecuteScalar();
if(TextBox1.Text==pwd)
{
if(TextBox2.Text==TextBox3.Text)
{
SqlCommand updateCmd = new SqlCommand("update PWS set Password='"+TextBox2.Text+"' where UserId="+UserId.ToString(),conn);
cmd.ExecuteNoQuery();
}
else
Response.Write("<script>alert('两次输入的新密码不一致!')</script>");
}
else
Response.Write("<script>alert('密码错误!')</script>");
conn.Close();
------解决方案--------------------
try
{
//若数据库连接的当前状态是关闭的,则打开连接
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
SqlCommand cmd = new SqlCommand(DeleteString, conn);
cmd.CommandType = CommandType.Text;
intCount = cmd.ExecuteNonQuery();
return intCount > 0;
}
catch (Exception e)
{
strError = "数据更新失败:" + e.Message;
return null;
}
finally
{
if (conn.State != ConnectionState.Closed)
{
conn.Close();
}
}