您目前尚未登陆,请选择【登陆】或【注册
首页->其他源码->某大学学生管理系统(毕业设计)源码>>ST_addstudent.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:某大学学生管理系统(毕业设计)源码
当前文件:文件类型 StudentsInfo/ST_addstudent.aspx.cs打开代码结构图
普通视图
		            
1using System; 2using System.Collections; 3using System.ComponentModel; 4using System.Data; 5using System.Data.SqlClient; 6using System.Drawing; 7using System.Web; 8using System.Web.SessionState; 9using System.Web.UI; 10using System.Web.UI.WebControls; 11using System.Web.UI.HtmlControls; 12using System.Configuration; 13 14namespace STGROUP 15{ 16 /// <summary> 17 /// ST_addstudent 的摘要说明。 18 /// </summary> 19 public class ST_addstudent : System.Web.UI.Page 20 { 21 protected System.Web.UI.WebControls.TextBox st_tbx_id; 22 protected System.Web.UI.WebControls.TextBox st_tbx_name; 23 protected System.Web.UI.WebControls.TextBox st_tbx_nation; 24 protected System.Web.UI.WebControls.TextBox st_tbx_birthst_day; 25 protected System.Web.UI.WebControls.TextBox st_tbx_time; 26 protected System.Web.UI.WebControls.TextBox st_tbx_home; 27 protected System.Web.UI.WebControls.TextBox st_tbx_else; 28 protected System.Web.UI.WebControls.DropDownList st_ddl_sex; 29 protected System.Web.UI.WebControls.Button st_btn_ok; 30 protected System.Web.UI.WebControls.CustomValidator st_cv_id; 31 protected System.Web.UI.WebControls.Label st_lbl_note; 32 protected System.Web.UI.WebControls.Button st_btn_reset; 33 protected System.Web.UI.WebControls.RequiredFieldValidator st_rfv_name; 34 protected System.Web.UI.WebControls.RequiredFieldValidator st_rfv_id; 35 protected System.Web.UI.WebControls.RequiredFieldValidator st_rfv_nation; 36 protected System.Web.UI.WebControls.RequiredFieldValidator st_rfv_birthst_day; 37 protected System.Web.UI.WebControls.RequiredFieldValidator st_rfv_time; 38 protected System.Web.UI.WebControls.RequiredFieldValidator st_rfv_class; 39 protected System.Web.UI.WebControls.RequiredFieldValidator st_rfv_home; 40 protected System.Web.UI.WebControls.DropDownList st_ddl_class; 41 SqlConnection st_conn; 42 private void Page_Load(object sender, System.EventArgs e) 43 {//班级名称下拉列表框绑定 44 string st_connstr= ConfigurationSettings.AppSettings["st_dbconn"]; 45 SqlConnection st_conn1=new SqlConnection(st_connstr); 46 if(!IsPostBack) 47 { 48 st_conn1.Open (); 49 //查询所有的班级名称 50 string mysql="select * from ST_class"; 51 SqlCommand st_comm1=new SqlCommand (mysql,st_conn1); 52 SqlDataReader st_dr1=st_comm1.ExecuteReader (); 53 //将查出的班级作为下拉列表的数据项 54 while(st_dr1.Read ()) 55 { 56 st_ddl_class.Items .Add (new ListItem(st_dr1["ST_Class_name"].ToString() ,st_dr1["ST_Class_id"].ToString()) ); 57 } 58 st_conn1.Close (); 59 } 60 // 在此处放置用户代码以初始化页面 61 st_conn=new SqlConnection(st_connstr); 62 } 63 64 Web Form Designer generated code 86 87 private void st_btn_ok_Click(object sender, System.EventArgs e) 88 { 89 SqlCommand st_comm=new SqlCommand("insert_student_1",st_conn); 90 st_comm.CommandType=CommandType.StoredProcedure; 91 try 92 { 93 st_comm.Parameters.Add(new SqlParameter("@Student_id",SqlDbType.VarChar,50)); 94 st_comm.Parameters["@Student_id"].Value=st_tbx_id.Text; 95 st_comm.Parameters.Add(new SqlParameter("@Student_name",SqlDbType.VarChar,50)); 96 st_comm.Parameters["@Student_name"].Value=st_tbx_name.Text; 97 st_comm.Parameters.Add(new SqlParameter("@Student_sex",SqlDbType.Char,10)); 98 st_comm.Parameters["@Student_sex"].Value=st_ddl_sex.SelectedItem.Value; 99 st_comm.Parameters.Add(new SqlParameter("@Student_nation",SqlDbType.Char,10)); 100 st_comm.Parameters["@Student_nation"].Value=st_tbx_nation.Text; 101 st_comm.Parameters.Add(new SqlParameter("@Student_birthday",SqlDbType.DateTime,8)); 102 st_comm.Parameters["@Student_birthday"].Value=st_tbx_birthst_day.Text; 103 st_comm.Parameters.Add(new SqlParameter("@Student_time",SqlDbType.DateTime,8)); 104 st_comm.Parameters["@Student_time"].Value=st_tbx_time.Text; 105 st_comm.Parameters.Add(new SqlParameter("@Student_classid",SqlDbType.VarChar,50)); 106 st_comm.Parameters["@Student_classid"].Value=st_ddl_class.SelectedItem.Value; 107 st_comm.Parameters.Add(new SqlParameter("@Student_home",SqlDbType.VarChar,50)); 108 st_comm.Parameters["@Student_home"].Value=st_tbx_home.Text; 109 st_comm.Parameters.Add(new SqlParameter("@Student_else",SqlDbType.VarChar,50)); 110 st_comm.Parameters["@Student_else"].Value=st_tbx_else.Text; 111 st_comm.Connection.Open(); 112 st_comm.ExecuteNonQuery(); 113 st_comm.Connection.Close(); 114 st_insert(); 115 } 116 catch 117 { 118 st_lbl_note.Text="添加失败,请检查输入!"; 119 st_lbl_note.Style["color"]="red"; 120 } 121 122 } 123 public void st_insert() 124 { 125 string strsl="insert into ST_users(ST_User_id,ST_User_password,ST_User_power) values(@User_id,@User_pwd,0)"; 126 SqlCommand st_comm=new SqlCommand(strsl,st_conn); 127 st_comm.Parameters.Add(new SqlParameter("@User_id",SqlDbType.VarChar,50)); 128 st_comm.Parameters["@User_id"].Value=st_tbx_id.Text; 129 st_comm.Parameters.Add(new SqlParameter("@User_pwd",SqlDbType.VarChar,50)); 130 st_comm.Parameters["@User_pwd"].Value=st_tbx_id.Text; 131 st_comm.Connection.Open(); 132 try 133 { 134 st_comm.ExecuteNonQuery(); 135 Response.Redirect("ST_student.aspx"); 136 } 137 catch(SqlException) 138 { 139 st_lbl_note.Text="添加失败"; 140 st_lbl_note.Style["color"]="red"; 141 } 142 st_comm.Connection.Close(); 143 } 144 145 private void st_btn_reset_Click(object sender, System.EventArgs e) 146 { 147 Response.Redirect("ST_addstudent.aspx"); 148 } 149 //验证所填的学生id是否已经存在 150 protected void st_cv_id_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args) 151 { 152 //获得数据库连接字符串 153 string st_connstr= ConfigurationSettings.AppSettings["st_dbconn"]; 154 //建立连接 155 st_conn=new SqlConnection(st_connstr); 156 //打开连接 157 st_conn.Open(); 158 //创建命令字符串 159 SqlCommand st_comm=new SqlCommand("select_student_1",st_conn); 160 //指定为调用存储过程 161 st_comm.CommandType=CommandType.StoredProcedure; 162 //添加参数 163 st_comm.Parameters.Add("@Student_id",SqlDbType.VarChar,50); 164 st_comm.Parameters["@Student_id"].Value=st_tbx_id.Text; 165 //生成结果集 166 SqlDataReader st_dr=st_comm.ExecuteReader(); 167 //存在性判断,返回结果 168 if(st_dr.Read()) 169 { 170 args.IsValid=false; 171 } 172 else 173 { 174 args.IsValid=true; 175 } 176 //关闭连接 177 st_conn.Close(); 178 } 179 180 } 181} 182
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:某大学学生管理系统(毕业设计)源码
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号