
课程4上课日志4+三层架构
5页1、课程4 三层架构让代码结构更清晰 上课日志4一、复习、回顾实例4-3主要知识要点验证用户是否登录(Page_Load事件),Session超时时间,注销退出的两种实现方法,C#中的null与数据库中的空值的理解、数据库字段值为空值在读取时处理方法(要用数据读取器读取的时候、要为文本框赋值的时候、要替换Sql语句中的占位符的时候)、数据读取器字段序号与数据读取器.GetInt32(字段序号)的区别、进一步领悟三层架构项目的开发方法。下面二、三为在实例4-3的基础上增加添加学生信息、删除学生信息功能简称为实例4-4二、为实例4-4实现添加学生信息功能1、表现层界面设计 复制UpdateStudent.aspx代码修改即可。lblId可以删除2、编写添加学生信息的数据访问层代码public int InsertStudent(Student stu) string sql = insert into Student values(stunum,stuname,stuclass,subject,stuage,stuphone,stugender) ; SqlParameter paras =
2、new SqlParameter new SqlParameter(stunum,stu.StuNum), new SqlParameter(stuname,stu.StuName), new SqlParameter(stuclass,stu.StuClass), new SqlParameter(subject,stu.Subject),new SqlParameter(stuage,stu.StuAge=null?DBNull.Value:(object)stu.StuAge), new SqlParameter(stuphone,stu.StuPhone), new SqlParameter(stugender,stu.StuGender), ; int count = SqlHelper.ExecuteNonQuery(sql, paras); return count; public int SelectCount(string StuNum) string sql = select count(*) from Student where StuNum=StuNum; Sq
3、lParameter para = new SqlParameter(StuNum, StuNum); int count = Convert.ToInt32(SqlHelper.ExecuteScalar(sql, para); return count; 3、编写添加学生信息的业务逻辑层代码 public bool InsertStudent(Student stu) return dal.InsertStudent(stu) 0; public bool SelectCount(string StuNum) return dal.SelectCount(StuNum) 0; 4、编写添加学生信息的表现层代码private StudentBll bll = new StudentBll(); protected void Page_Load(object sender, EventArgs e) if (SessionUserName = null) SessionUserName = ; /Response.Redirect(Login.aspx); Response.Write
《课程4上课日志4+三层架构》由会员 y****g分享,可在线阅读,更多相关《课程4上课日志4+三层架构》请在金锄头文库上搜索。