/*根据selectId获取某条选课信息记录*/ public static ENTITY.StudentSelectCourseInfo getSomeStudentSelectCourseInfo(int selectId) { /*构建查询sql*/ string sql = "select * from StudentSelectCourseInfo where selectId=" + selectId; SqlDataReader DataRead = DBHelp.ExecuteReader(sql, null); ENTITY.StudentSelectCourseInfo studentSelectCourseInfo = new ENTITY.StudentSelectCourseInfo(); /*如果查询存在记录,就包装到对象中返回*/ if (DataRead.Read()) { studentSelectCourseInfo.selectId = Convert.ToInt32(DataRead["selectId"]); studentSelectCourseInfo.studentNumber = DataRead["studentNumber"].ToString(); studentSelectCourseInfo.courseNumber = DataRead["courseNumber"].ToString(); } return(studentSelectCourseInfo); }
/*添加选课信息实现*/ public static bool AddStudentSelectCourseInfo(ENTITY.StudentSelectCourseInfo studentSelectCourseInfo) { string sql = "insert into StudentSelectCourseInfo(studentNumber,courseNumber) values(@studentNumber,@courseNumber)"; /*构建sql参数*/ SqlParameter[] parm = new SqlParameter[] { new SqlParameter("@studentNumber", SqlDbType.VarChar), new SqlParameter("@courseNumber", SqlDbType.VarChar) }; /*给参数赋值*/ parm[0].Value = studentSelectCourseInfo.studentNumber; //学生对象 parm[1].Value = studentSelectCourseInfo.courseNumber; //课程对象 /*执行sql进行添加*/ return((DBHelp.ExecuteNonQuery(sql, parm) > 0) ? true : false); }
/*更新选课信息实现*/ public static bool EditStudentSelectCourseInfo(ENTITY.StudentSelectCourseInfo studentSelectCourseInfo) { string sql = "update StudentSelectCourseInfo set studentNumber=@studentNumber,courseNumber=@courseNumber where selectId=@selectId"; /*构建sql参数信息*/ SqlParameter[] parm = new SqlParameter[] { new SqlParameter("@studentNumber", SqlDbType.VarChar), new SqlParameter("@courseNumber", SqlDbType.VarChar), new SqlParameter("@selectId", SqlDbType.Int) }; /*为参数赋值*/ parm[0].Value = studentSelectCourseInfo.studentNumber; parm[1].Value = studentSelectCourseInfo.courseNumber; parm[2].Value = studentSelectCourseInfo.selectId; /*执行更新*/ return((DBHelp.ExecuteNonQuery(sql, parm) > 0) ? true : false); }