/*根据classNo获取某条班级信息记录*/ public static ENTITY.Class_ getSomeClass_(string classNo) { /*构建查询sql*/ string sql = "select * from Class_ where classNo='" + classNo + "'"; SqlDataReader DataRead = DBHelp.ExecuteReader(sql, null); ENTITY.Class_ class_ = new ENTITY.Class_(); /*如果查询存在记录,就包装到对象中返回*/ if (DataRead.Read()) { class_.classNo = DataRead["classNo"].ToString(); class_.className = DataRead["className"].ToString(); class_.banzhuren = DataRead["banzhuren"].ToString(); class_.beginTime = Convert.ToDateTime(DataRead["beginTime"].ToString()); } return(class_); }
/*更新班级信息实现*/ public static bool EditClass_(ENTITY.Class_ class_) { string sql = "update Class_ set className=@className,banzhuren=@banzhuren,beginTime=@beginTime where classNo=@classNo"; /*构建sql参数信息*/ SqlParameter[] parm = new SqlParameter[] { new SqlParameter("@className", SqlDbType.VarChar), new SqlParameter("@banzhuren", SqlDbType.VarChar), new SqlParameter("@beginTime", SqlDbType.DateTime), new SqlParameter("@classNo", SqlDbType.VarChar) }; /*为参数赋值*/ parm[0].Value = class_.className; parm[1].Value = class_.banzhuren; parm[2].Value = class_.beginTime; parm[3].Value = class_.classNo; /*执行更新*/ return((DBHelp.ExecuteNonQuery(sql, parm) > 0) ? true : false); }
/*添加班级信息实现*/ public static bool AddClass_(ENTITY.Class_ class_) { string sql = "insert into Class_(classNo,className,banzhuren,beginTime) values(@classNo,@className,@banzhuren,@beginTime)"; /*构建sql参数*/ SqlParameter[] parm = new SqlParameter[] { new SqlParameter("@classNo", SqlDbType.VarChar), new SqlParameter("@className", SqlDbType.VarChar), new SqlParameter("@banzhuren", SqlDbType.VarChar), new SqlParameter("@beginTime", SqlDbType.DateTime) }; /*给参数赋值*/ parm[0].Value = class_.classNo; //班级编号 parm[1].Value = class_.className; //班级名称 parm[2].Value = class_.banzhuren; //班主任姓名 parm[3].Value = class_.beginTime; //开办日期 /*执行sql进行添加*/ return((DBHelp.ExecuteNonQuery(sql, parm) > 0) ? true : false); }