您目前尚未登陆,请选择【登陆】或【注册
首页->行政办公->Asp.net简单网络选课系统源码>>studentElect.aspx.cs>>代码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:Asp.net简单网络选课系统源码


当前文件路径:MyElectCourse/studentElect.aspx.cs 文件类型
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Collections; 5using System.Web; 6using System.Web.Security; 7using System.Web.UI; 8using System.Web.UI.WebControls; 9using System.Web.UI.WebControls.WebParts; 10using System.Web.UI.HtmlControls; 11using System.Data.SqlClient; 12 13public partial class StudentElect : System.Web.UI.Page 14{ 15 protected void Page_Load(object sender, EventArgs e) 16 { 17 18 } 19 //GridView1控件的RowCommand事件 20 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 21 { 22 if (e.CommandName == "select") //如果单击的是“选修”按钮 23 { 24 int index = Convert.ToInt32(e.CommandArgument); //取出选修课程所在的行索引 25 DataKey key = GridView1.DataKeys[index]; //创建DataKey集合接收该行的主键 26 string courceID = GridView1.DataKeys[index].Values[0].ToString().Trim();//取出课程编号主键值 27 string teaID = GridView1.DataKeys[index].Values[1].ToString().Trim(); //取出教师编号主键值 28 string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; 29 string SqlStr = "insert into Elect(stuID,courceID,teaID) values('" + Session["userName"].ToString() + "','" + courceID + "','" + teaID + "')"; 30 try 31 { 32 SqlConnection conn = new SqlConnection(connStr);//创建连接对象 33 if (conn.State.ToString() == "Closed") //如果连接关闭,打开连接 34 conn.Open(); 35 SqlCommand comm = new SqlCommand(SqlStr, conn); 36 comm.ExecuteNonQuery(); //执行插入选修课程 37 comm.Dispose(); 38 if (conn.State.ToString() == "Open") //如果连接打开,关闭连接 39 conn.Close(); 40 } 41 catch (Exception ex) //异常处理 42 { 43 Response.Write("数据库错误,错误原因:" + ex.Message); 44 Response.End(); 45 } 46 } 47 } 48 49 //GridView2控件的RowCommand事件 50 protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e) 51 { 52 if (e.CommandName == "shanchu") //如果单击的是“选修”按钮 53 { 54 int index = Convert.ToInt32(e.CommandArgument); //取出选修课程所在的行索引 55 DataKey key = GridView1.DataKeys[index]; //创建DataKey集合接收该行的主键 56 string stuID = GridView2.DataKeys[index].Values[0].ToString().Trim(); //取出学号主键值 57 string courceID = GridView1.DataKeys[index].Values[0].ToString().Trim();//取出课程编号主键值 58 string teaID = GridView1.DataKeys[index].Values[1].ToString().Trim(); //取出教师编号主键值 59 string userName = Session["userName"].ToString(); 60 string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; 61 string SqlStr = "delete from Elect where stuID='" + userName + "' and courceID='" + courceID + "' and teaID='" + teaID + "'"; 62 try 63 { 64 SqlConnection conn = new SqlConnection(connStr);//创建连接对象 65 if (conn.State.ToString() == "Closed") //如果连接关闭,打开连接 66 conn.Open(); 67 SqlCommand comm = new SqlCommand(SqlStr, conn); 68 comm.ExecuteNonQuery(); //执行插入选修课程 69 comm.Dispose(); 70 if (conn.State.ToString() == "Open") //如果连接打开,关闭连接 71 conn.Close(); 72 } 73 catch (Exception ex) //异常处理 74 { 75 Response.Write("数据库错误,错误原因:" + ex.Message); 76 Response.End(); 77 } 78 } 79 } 80} 81
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:Asp.net简单网络选课系统源码

- IFNuke1.1.0版源码

- 快乐商城全站源码

- 通过数据的添加删除学三层入..

- Asp.net汉字转拼音源码(全)

- 简单的XML学生信息系统(注释..

- 山建大校内购物网源码(NBear..

- 综合示例源码(文章、论坛、会..

- 特瑞飞家教信息平台源码

51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号