📄 stu_pas.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration ;
using System.Data .OleDb ;
using System.Data.SqlClient ;
namespace graduate.stu
{
/// <summary>
/// stu_pas 的摘要说明。
/// </summary>
public class stu_pas : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button tj;
string myConnString=ConfigurationSettings.AppSettings ["SQLconnectionString"];
protected System.Web.UI.WebControls.TextBox txt_psw;
protected System.Web.UI.WebControls.TextBox txt_psw1;
string sql="";
protected System.Web.UI.WebControls.Label lab_name;
string studentid="";
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
tj.Attributes .Add ("onclick","return confirm_1();");
Session["studentid"] = "10001";
studentid=Convert.ToString (Session["studentid"]);
if(!IsPostBack)
{
SqlConnection conn = new SqlConnection(myConnString);
sql="select studentname from BYSJ.studentbaseinfo where studentid='"+studentid+"'";
try
{
conn.Open();
SqlDataAdapter adapter1 = new SqlDataAdapter(sql, conn);
DataSet cla=new DataSet ();
adapter1.Fill(cla);
lab_name.Text =Convert.ToString (cla.Tables ["table"].Rows[0].ItemArray [0]);
}
catch(SqlException ex)
{
Response.Write ("<script>");
Response.Write ("alert('数据库连接出错!')");
Response.Write ("</script>");
}
finally
{
conn.Close ();
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.tj.Click += new System.EventHandler(this.tj_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void tj_Click(object sender, System.EventArgs e)
{
string psw = txt_psw.Text .TrimEnd ();
SqlConnection conn = new SqlConnection(myConnString);
sql="update bysj.studentbaseinfo set password = '"+psw+"' where studentid='"+studentid+"'";
SqlCommand cmd = new SqlCommand (sql,conn);
try
{
conn.Open();
cmd.ExecuteNonQuery ();
Response.Write ("<script>");
Response.Write ("alert('密码修改成功!');");
Response.Write("window.close();");
Response.Write("</script>");
}
catch(SqlException ex)
{
Response.Write ("<script>");
Response.Write ("alert('数据库连接出错!')");
Response.Write ("</script>");
}
finally
{
conn.Close ();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -