📄 stu_mod.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_info 的摘要说明。
/// </summary>
public class stu_info : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox textbox_tel;
protected System.Web.UI.WebControls.TextBox textbox_mail;
protected System.Web.UI.WebControls.Label lab_xh;
protected System.Web.UI.WebControls.Label lab_name;
protected System.Web.UI.WebControls.Label lab_year;
protected System.Web.UI.WebControls.Label lab_class;
protected System.Web.UI.WebControls.Label lab_xf;
protected System.Web.UI.WebControls.Button tj;
string sql="";
string studentid="";
string myConnString=ConfigurationSettings.AppSettings ["SQLconnectionString"];
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 studentid,studentname,credit,enteryear,telephone,email,classname from BYSJ.studentbaseinfo a , bysj.classinfo b where studentid='"+studentid+"' and a.classid=b.classid";
try
{
conn.Open();
SqlDataAdapter adapter1 = new SqlDataAdapter(sql, conn);
DataSet cla=new DataSet ();
adapter1.Fill(cla);
lab_xh.Text = Convert.ToString (cla.Tables ["table"].Rows [0].ItemArray [0]);
lab_name.Text =Convert.ToString (cla.Tables ["table"].Rows[0].ItemArray [1]);
lab_class.Text =Convert.ToString (cla.Tables ["table"].Rows[0].ItemArray [6]);
lab_year.Text = Convert.ToString (cla.Tables ["table"].Rows [0].ItemArray [3]);
lab_xf.Text =Convert.ToString (cla.Tables ["table"].Rows[0].ItemArray [2]);
textbox_tel.Text = Convert.ToString (cla.Tables ["table"].Rows [0].ItemArray [4]);
textbox_mail.Text = Convert.ToString (cla.Tables ["table"].Rows [0].ItemArray [5]);
}
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 tel=textbox_tel.Text .ToString () ;
string mail=textbox_mail.Text.Trim () ;
SqlConnection conn = new SqlConnection(myConnString);
try
{
conn.Open();
sql="update bysj.studentbaseinfo set telephone='"+tel+"',email='"+mail+"' where studentid='"+studentid+"'";
SqlCommand cmd = new SqlCommand (sql,conn);
cmd.CommandText =sql;
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 + -