本文介绍了密码无法在asp.net中更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
public partial class Admin_Changepaswword : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str = null;
SqlCommand com;
byte up;
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from registration ";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
if (txtcnfpass.Text == reader["password"].ToString())
{
up = 0;
}
}
reader.Close();
con.Close();
if (up == 0)
{
con.Open();
str = "update login set password="+txtnewpass.Text+" where id='1'";
com = new SqlCommand(str, con);
com.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 50));
com.Parameters["@Password"].Value = txtnewpass.Text;
// com.ExecuteNonQuery();
con.Close();
Label1.Text = "Password changed Successfully";
}
else
{
Label1.Text = "Please enter correct Current password";
}
}
}
推荐答案
con.Open();
str = "update login set password="+txtnewpass.Text+" where id='1'";
com = new SqlCommand(str, con);
//com.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 50));
//com.Parameters["@Password"].Value = txtnewpass.Text;
com.ExecuteNonQuery();
con.Close();
这篇关于密码无法在asp.net中更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!