📄 st_addstudentcourse.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace STGROUP
{
/// <summary>
/// ST_addstudentcourse 的摘要说明。
/// </summary>
public class ST_addstudentcourse : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList st_ddl_course;
protected System.Web.UI.WebControls.DropDownList st_ddl_class;
protected System.Web.UI.WebControls.TextBox st_tbx_year;
protected System.Web.UI.WebControls.Button st_btn_ok;
protected System.Web.UI.WebControls.Label st_lbl_note;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string st_connstr= ConfigurationSettings.AppSettings["st_dbconn"];
//连接本地计算机的sms数据库
SqlConnection st_conn0= new SqlConnection (st_connstr);
if(!IsPostBack)
{
//课程名称下拉列表框绑定
st_conn0.Open ();
string mysql1="select * from ST_course where ST_Course_kind='0'or ST_Course_kind='1'";
SqlCommand st_comm1=new SqlCommand (mysql1,st_conn0);
SqlDataReader st_dr1=st_comm1.ExecuteReader ();
while(st_dr1.Read ())
{
st_ddl_course.Items .Add (new ListItem(st_dr1["ST_Course_name"].ToString() ,st_dr1["ST_Course_id"].ToString()) );
}
st_conn0.Close ();
//班级名称下拉列表框绑定
st_conn0.Open ();
string st_sql2="select * from ST_class";
SqlCommand st_comm2=new SqlCommand (st_sql2,st_conn0);
SqlDataReader st_dr2=st_comm2.ExecuteReader ();
while(st_dr2.Read ())
{
st_ddl_class.Items .Add (new ListItem(st_dr2["ST_Class_name"].ToString() ,st_dr2["ST_Class_id"].ToString()) );
}
st_conn0.Close ();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.st_btn_ok.Click += new System.EventHandler(this.st_btn_ok_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void st_btn_ok_Click(object sender, System.EventArgs e)
{
string st_connstr= ConfigurationSettings.AppSettings["st_dbconn"];
SqlConnection st_conn= new SqlConnection (st_connstr);
st_conn.Open();
string st_sqlstr="insert into ST_student_course(ST_Student_id,ST_Course_id,ST_Course_year) (select ST_Student_id,@Course_id,@Course_year from ST_student where ST_Student_classid=@classid) ";
SqlCommand st_comm=new SqlCommand(st_sqlstr,st_conn);
st_comm.Parameters.Add(new SqlParameter("@classid",SqlDbType.VarChar,50));
st_comm.Parameters["@classid"].Value=st_ddl_class.SelectedItem.Value;
st_comm.Parameters.Add(new SqlParameter("@Course_id",SqlDbType.VarChar,50));
st_comm.Parameters["@Course_id"].Value=st_ddl_course.SelectedItem.Value;
st_comm.Parameters.Add(new SqlParameter("@Class_id",SqlDbType.VarChar,50));
st_comm.Parameters["@Class_id"].Value=st_ddl_class.SelectedItem.Value;
st_comm.Parameters.Add(new SqlParameter("@Course_year",SqlDbType.VarChar,50));
st_comm.Parameters["@Course_year"].Value=st_tbx_year.Text;
try
{
st_comm.ExecuteNonQuery();
st_lbl_note.Text="添加成功,请返回";
}
catch(SqlException)
{
st_lbl_note.Text="添加失败";
st_lbl_note.Style["color"]="red";
}
st_conn.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -