/// <summary> /// 得到一个对象实体 /// </summary> public ArticleVsImageModel GetModel(string AricleId, string ImgId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select AricleId, ImgId, VsType "); strSql.Append(" from ArticleVsImage "); strSql.Append(" where AricleId=@AricleId and ImgId=@ImgId "); SqlParameter[] parameters = { new SqlParameter("@AricleId", SqlDbType.VarChar, 50), new SqlParameter("@ImgId", SqlDbType.VarChar, 50) }; parameters[0].Value = AricleId; parameters[1].Value = ImgId; ArticleVsImageModel model = new ArticleVsImageModel(); DataSet ds = helper.ExecSqlReDs(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { model.AricleId = ds.Tables[0].Rows[0]["AricleId"].ToString(); model.ImgId = ds.Tables[0].Rows[0]["ImgId"].ToString(); model.VsType = ds.Tables[0].Rows[0]["VsType"].ToString(); return(model); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(ArticleVsImageModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ArticleVsImage("); strSql.Append("AricleId,ImgId,VsType"); strSql.Append(") values ("); strSql.Append("@AricleId,@ImgId,@VsType"); strSql.Append(") "); SqlParameter[] parameters = { new SqlParameter("@AricleId", SqlDbType.VarChar, 50), new SqlParameter("@ImgId", SqlDbType.VarChar, 50), new SqlParameter("@VsType", SqlDbType.VarChar, 10) }; parameters[0].Value = model.AricleId; parameters[1].Value = model.ImgId; parameters[2].Value = model.VsType; bool result = false; strSql.Append(Common.SqlStrHelper.BindImgSqlStr(model.ImgId)); //顺便绑定 try { helper.ExecSqlReInt(strSql.ToString(), parameters); result = true; } catch (Exception ex) { this.helper.Close(); throw ex; } finally { } return(result); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ArticleVsImageModel model) { bool reValue = true; int reCount = 0; StringBuilder strSql = new StringBuilder(); strSql.Append("update ArticleVsImage set "); strSql.Append(" AricleId = @AricleId , "); strSql.Append(" ImgId = @ImgId , "); strSql.Append(" VsType = @VsType "); strSql.Append(" where AricleId=@AricleId and ImgId=@ImgId "); SqlParameter[] parameters = { new SqlParameter("@AricleId", SqlDbType.VarChar, 50), new SqlParameter("@ImgId", SqlDbType.VarChar, 50), new SqlParameter("@VsType", SqlDbType.VarChar, 10) }; parameters[0].Value = model.AricleId; parameters[1].Value = model.ImgId; parameters[2].Value = model.VsType; try {//异常处理 reCount = this.helper.ExecSqlReInt(strSql.ToString(), parameters); } catch (Exception ex) { this.helper.Close(); throw ex; } if (reCount <= 0) { reValue = false; } return(reValue); }