showstudent.ascx.cs

来自「电子选课系统 电子选课系统电子选课系统电子选课系统」· CS 代码 · 共 79 行

CS
79
字号
namespace Park.StudentSystem
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
	using System.Data.SqlClient;
	using Park.Common;
	/// <summary>
	///		ShowStuentInfo 的摘要说明。
	/// </summary>
	public class ShowStuent : System.Web.UI.UserControl
	{
		protected System.Web.UI.WebControls.Label lbId;
		protected System.Web.UI.WebControls.Label lbName;
		protected System.Web.UI.WebControls.Label lbClass;

		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(!IsPostBack)
			{
				loadData(HttpContext.Current.User.Identity.Name);
			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		设计器支持所需的方法 - 不要使用代码编辑器
		///		修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
		private void loadData(string id)
		{
			SqlConnection myConnection=Utils.GetConnection();

			SqlCommand myCommand = new SqlCommand("StudentSystem_Get_StudentInfo", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;

			SqlParameter TeacherID = new SqlParameter("@id", SqlDbType.NVarChar,20);
			TeacherID.Value = id;
			myCommand.Parameters.Add(TeacherID);
			myConnection.Open();

			SqlDataReader result = myCommand.ExecuteReader();
			if(result.Read())
			{
				this.lbId.Text = result["ID"].ToString();
				this.lbName.Text = result["Name"].ToString();
				this.lbClass.Text = result["BelongingClass"].ToString();
			}
			result.Close();

			myCommand.Dispose();
			myConnection.Dispose();

		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?