/*根据scoreId获取某条成绩信息记录*/ public static ENTITY.Score_ getSomeScore_(int scoreId) { /*构建查询sql*/ string sql = "select * from Score_ where scoreId=" + scoreId; SqlDataReader DataRead = DBHelp.ExecuteReader(sql, null); ENTITY.Score_ score_ = new ENTITY.Score_(); /*如果查询存在记录,就包装到对象中返回*/ if (DataRead.Read()) { score_.scoreId = Convert.ToInt32(DataRead["scoreId"]); score_.studentNo = DataRead["studentNo"].ToString(); score_.courseNo = DataRead["courseNo"].ToString(); score_.termId = Convert.ToInt32(DataRead["termId"]); score_.score = float.Parse(DataRead["score"].ToString()); } return(score_); }
/*添加成绩信息实现*/ public static bool AddScore_(ENTITY.Score_ score_) { string sql = "insert into Score_(studentNo,courseNo,termId,score) values(@studentNo,@courseNo,@termId,@score)"; /*构建sql参数*/ SqlParameter[] parm = new SqlParameter[] { new SqlParameter("@studentNo", SqlDbType.VarChar), new SqlParameter("@courseNo", SqlDbType.VarChar), new SqlParameter("@termId", SqlDbType.Int), new SqlParameter("@score", SqlDbType.Float) }; /*给参数赋值*/ parm[0].Value = score_.studentNo; //所属学生 parm[1].Value = score_.courseNo; //所属课程 parm[2].Value = score_.termId; //所在学期 parm[3].Value = score_.score; //成绩得分 /*执行sql进行添加*/ return((DBHelp.ExecuteNonQuery(sql, parm) > 0) ? true : false); }
/*更新成绩信息实现*/ public static bool EditScore_(ENTITY.Score_ score_) { string sql = "update Score_ set studentNo=@studentNo,courseNo=@courseNo,termId=@termId,score=@score where scoreId=@scoreId"; /*构建sql参数信息*/ SqlParameter[] parm = new SqlParameter[] { new SqlParameter("@studentNo", SqlDbType.VarChar), new SqlParameter("@courseNo", SqlDbType.VarChar), new SqlParameter("@termId", SqlDbType.Int), new SqlParameter("@score", SqlDbType.Float), new SqlParameter("@scoreId", SqlDbType.Int) }; /*为参数赋值*/ parm[0].Value = score_.studentNo; parm[1].Value = score_.courseNo; parm[2].Value = score_.termId; parm[3].Value = score_.score; parm[4].Value = score_.scoreId; /*执行更新*/ return((DBHelp.ExecuteNonQuery(sql, parm) > 0) ? true : false); }