码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET 修改密码代码

时间:2016-07-09 12:12:47      阅读:467      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class changepassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //读取web.config配置文件数据库连接字符串
        string strConstring = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        //创建sql数据库连接对象
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = strConstring;
        conn.Open();
        try
        {
            SqlCommand selectedcmd = new SqlCommand("select from users where userid=‘"+Session["userid"].ToString()+"‘and password=‘"+origin.Text.Trim()+"",conn);
            SqlDataReader sdr = selectedcmd.ExecuteReader();
            if (sdr.Read())
            {
                SqlCommand updatecmd = new SqlCommand("update users set password=‘" + newpwd.Text.Trim() + "‘where userid=‘" + Session["userid"].ToString() + "", conn);
                int i = updatecmd.ExecuteNonQuery();
                if (i == 1)
                {
                    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();
        }
    }

 

ASP.NET 修改密码代码

标签:

原文地址:http://www.cnblogs.com/XACOOL/p/5655454.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!