ModifyInfo.aspx.cs代码

涉及修改密码,提交请求 操作,修改数据库内容
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.UI;
 6 using System.Web.UI.WebControls;
 7 using System.Data.SqlClient;
 8 using System.Data.Sql;
 9 using System.Data;
10 
11 public partial class ModifyInfo : System.Web.UI.Page
12 {
13     protected void Page_Load(object sender, EventArgs e)
14     {
15 
16     }
17     //修改界面,修改变更请求
18     protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
19     {
20         e.Cancel = true;//取消修改事件发到系统框架
21         //获得输入信息,并组成SQL语句
22         string bgqq = ((TextBox)FormView1.FindControl("stdBgqqTextBox")).Text;
23         string stdXh = Session["stdXh"].ToString();
24         string sql = "update stdInfo set stdBgqq=@bgqq where stdXh=@stdXh";
25         SqlParameter[] param ={
26             new SqlParameter("@bgqq",SqlDbType.Text),
27             new SqlParameter("@stdXh",SqlDbType.Char)
28         };
29         param[0].Value = bgqq;
30         param[1].Value = stdXh;
31         //执行SQL语句,修改数据库
32         sqlHelp.ExecuteNoneQuery(sqlHelp.ConnectionStringLcalTransaction, CommandType.Text, sql, param);
33         //重新加载本页面,刷新数据
34         Response.Redirect("ModifyInfo.aspx?stdXh=" + stdXh);
35     }
36     //修改密码按钮处理事件
37     protected void LinkButton1_Click(object sender, EventArgs e)
38     {
39         //获得输入的新旧密码和登陆时保存的用户名
40         string oldPassword = txtOldPassword.Text.Replace("'", "");
41         string newPassword = txtNewPassword.Text.Replace("'", "");
42         string stdXh = Session["stdXh"].ToString();
43         //查询数据库 验证旧密码是否正确
44         string sql =
45             "select count(*) from stdInfo where stdXh=@stdXh and stdMm=@stdMm";
46         SqlParameter []param={
47             new SqlParameter("@stdXh",SqlDbType.Text),
48             new SqlParameter("@stdMm",SqlDbType.Text)
49         };
50         param[0].Value=stdXh;
51         param[1].Value=oldPassword;
52         int usercount=((int )(sqlHelp.ExecuteScalar(sqlHelp.ConnectionStringLcalTransaction,CommandType.Text,sql,param)));
53         if(usercount<=0)//如果查询不到记录,表示旧密码错误
54         {
55             labMsg.Text = "旧密码错误";
56         }
57         else{
58             //执行数据库操作修改密码
59             string updatesql=
60                 "update stdInfo set stdMm=@stdMm where stdXh=@stdxh";
61             SqlParameter []updateParam={
62                  new SqlParameter("@stdXh",SqlDbType.Text),
63                  new SqlParameter("@stdMm",SqlDbType.Text)
64             };
65             param[0].Value=stdXh;
66             param[1].Value=newPassword;
67             if(sqlHelp.ExecuteNoneQuery(sqlHelp.ConnectionStringLcalTransaction,CommandType.Text,updatesql,updateParam)>0)
68             {
69                 labMsg.Text="修改成功";
70             }
71             else
72             {
73                 labMsg.Text="修改失败";
74             }
75         }
76     }
77 }

 

你可能感兴趣的:(ModifyInfo.aspx.cs代码)