/// <summary> /// 更新一条数据 /// </summary> public bool Update(StudentMS.Model.S_C model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update S_C set "); strSql.Append("Score=@Score"); strSql.Append(" where SNO=@SNO and CNO=@CNO "); SqlParameter[] parameters = { new SqlParameter("@SNO", SqlDbType.VarChar, 50), new SqlParameter("@CNO", SqlDbType.VarChar, 50), new SqlParameter("@Score", SqlDbType.Float, 8) }; parameters[0].Value = model.SNO; parameters[1].Value = model.CNO; parameters[2].Value = model.Score; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public StudentMS.Model.S_C GetModel(string SNO, string CNO) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 SNO,CNO,Score from S_C "); strSql.Append(" where SNO=@SNO and CNO=@CNO "); SqlParameter[] parameters = { new SqlParameter("@SNO", SqlDbType.VarChar, 50), new SqlParameter("@CNO", SqlDbType.VarChar, 50) }; parameters[0].Value = SNO; parameters[1].Value = CNO; StudentMS.Model.S_C model = new StudentMS.Model.S_C(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { model.SNO = ds.Tables[0].Rows[0]["SNO"].ToString(); model.CNO = ds.Tables[0].Rows[0]["CNO"].ToString(); if (ds.Tables[0].Rows[0]["Score"].ToString() != "") { model.Score = decimal.Parse(ds.Tables[0].Rows[0]["Score"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public void Add(StudentMS.Model.S_C model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into S_C("); strSql.Append("SNO,CNO,Score)"); strSql.Append(" values ("); strSql.Append("@SNO,@CNO,@Score)"); SqlParameter[] parameters = { new SqlParameter("@SNO", SqlDbType.VarChar, 50), new SqlParameter("@CNO", SqlDbType.VarChar, 50), new SqlParameter("@Score", SqlDbType.Float, 8) }; parameters[0].Value = model.SNO; parameters[1].Value = model.CNO; parameters[2].Value = model.Score; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }