Asp.net 用户修改密码
下面是我的代码提示说有Format的那句错了但是不知道有什么不对的求大神看看protectedvoidButton1_Click1(objectsender,EventA...
下面是我的代码
提示说 有Format的那句错了 但是不知道有什么不对的 求大神看看
protected void Button1_Click1(object sender, EventArgs e)
{
SqlConnection cnn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename="
+ Server.MapPath(".") + "\\db.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand comm = new SqlCommand();
comm.Connection = cnn;
cnn.Open();
comm.CommandText = string.Format("select password from users where userid='{0}'", Session["userid"].ToString().Trim());
SqlDataReader sqlreader = comm.ExecuteReader();
if (sqlreader.Read())
{
if (sqlreader["password"].ToString().Trim() != TextBox2.Text.Trim()) Response.Write("原密码错误!");
else
{
cnn.Close();
try
{
cnn.Open();
SqlDataAdapter sqlada = new SqlDataAdapter(string.Format("select * from Table1 where userid='{0}'",
Session["userid"].ToString().Trim()), cnn);
SqlCommandBuilder sqlb = new SqlCommandBuilder(sqlada);
DataTable dt = new DataTable();
sqlada.Fill(dt);
//DataRow myrow = dt.Tables[0].NewRow();
//dt.Rows[0]["username"] = Session["user"].ToString().Trim();
dt.Rows[0]["password"] = TextBox3.Text.Trim();
sqlada.Update(dt);
dt.AcceptChanges();
Response.Redirect("login.aspx");
}
catch (Exception ex) { Response.Write(ex.Message.ToString() + "修改密码失败!"); }
}
}
} 展开
提示说 有Format的那句错了 但是不知道有什么不对的 求大神看看
protected void Button1_Click1(object sender, EventArgs e)
{
SqlConnection cnn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename="
+ Server.MapPath(".") + "\\db.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand comm = new SqlCommand();
comm.Connection = cnn;
cnn.Open();
comm.CommandText = string.Format("select password from users where userid='{0}'", Session["userid"].ToString().Trim());
SqlDataReader sqlreader = comm.ExecuteReader();
if (sqlreader.Read())
{
if (sqlreader["password"].ToString().Trim() != TextBox2.Text.Trim()) Response.Write("原密码错误!");
else
{
cnn.Close();
try
{
cnn.Open();
SqlDataAdapter sqlada = new SqlDataAdapter(string.Format("select * from Table1 where userid='{0}'",
Session["userid"].ToString().Trim()), cnn);
SqlCommandBuilder sqlb = new SqlCommandBuilder(sqlada);
DataTable dt = new DataTable();
sqlada.Fill(dt);
//DataRow myrow = dt.Tables[0].NewRow();
//dt.Rows[0]["username"] = Session["user"].ToString().Trim();
dt.Rows[0]["password"] = TextBox3.Text.Trim();
sqlada.Update(dt);
dt.AcceptChanges();
Response.Redirect("login.aspx");
}
catch (Exception ex) { Response.Write(ex.Message.ToString() + "修改密码失败!"); }
}
}
} 展开
1个回答
2016-06-28
展开全部
在注册的时候如果注册通过了将用户名和密码写到session里面if(注册通过){Session["UserName"]="123";Session["Password"]="123";}登录的时候直接取SessionstringUsername=Session["UserName"]ToString();stringPassword=Session["Password"]ToString();
追问
我的注册是在数据库里了 就没有用到Session 我感觉我是那个数据库语句不对 知道怎么改么
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询