Пример #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(HYTCWeiBo.Model.Favorites model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Favorites set ");

            strSql.Append(" favoriteId = @favoriteId , ");
            strSql.Append(" weiboId = @weiboId , ");
            strSql.Append(" authorName = @authorName  ");
            strSql.Append(" where favoriteId=@favoriteId  ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@favoriteId", SqlDbType.Int,     4),
                new SqlParameter("@weiboId",    SqlDbType.Int,     4),
                new SqlParameter("@authorName", SqlDbType.VarChar, 20)
            };

            parameters[0].Value = model.favoriteId;
            parameters[1].Value = model.weiboId;
            parameters[2].Value = model.authorName;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(HYTCWeiBo.Model.Favorites model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Favorites(");
            strSql.Append("favoriteId,weiboId,authorName");
            strSql.Append(") values (");
            strSql.Append("@favoriteId,@weiboId,@authorName");
            strSql.Append(") ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@favoriteId", SqlDbType.Int,     4),
                new SqlParameter("@weiboId",    SqlDbType.Int,     4),
                new SqlParameter("@authorName", SqlDbType.VarChar, 20)
            };

            parameters[0].Value = model.favoriteId;
            parameters[1].Value = model.weiboId;
            parameters[2].Value = model.authorName;
            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
Пример #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public HYTCWeiBo.Model.Favorites GetModel(int favoriteId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select favoriteId, weiboId, authorName  ");
            strSql.Append("  from Favorites ");
            strSql.Append(" where favoriteId=@favoriteId ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@favoriteId", SqlDbType.Int, 4)
            };
            parameters[0].Value = favoriteId;


            HYTCWeiBo.Model.Favorites model = new HYTCWeiBo.Model.Favorites();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["favoriteId"].ToString() != "")
                {
                    model.favoriteId = int.Parse(ds.Tables[0].Rows[0]["favoriteId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["weiboId"].ToString() != "")
                {
                    model.weiboId = int.Parse(ds.Tables[0].Rows[0]["weiboId"].ToString());
                }
                model.authorName = ds.Tables[0].Rows[0]["authorName"].ToString();

                return(model);
            }
            else
            {
                return(null);
            }
        }
Пример #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public HYTCWeiBo.Model.Favorites GetModel(int favoriteId)
        {
            StringBuilder strSql=new StringBuilder();
            strSql.Append("select favoriteId, weiboId, authorName  ");
            strSql.Append("  from Favorites ");
            strSql.Append(" where favoriteId=@favoriteId ");
                        SqlParameter[] parameters = {
                    new SqlParameter("@favoriteId", SqlDbType.Int,4)			};
            parameters[0].Value = favoriteId;

            HYTCWeiBo.Model.Favorites model=new HYTCWeiBo.Model.Favorites();
            DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);

            if(ds.Tables[0].Rows.Count>0)
            {
                                                if(ds.Tables[0].Rows[0]["favoriteId"].ToString()!="")
                {
                    model.favoriteId=int.Parse(ds.Tables[0].Rows[0]["favoriteId"].ToString());
                }
                                                                                                                                if(ds.Tables[0].Rows[0]["weiboId"].ToString()!="")
                {
                    model.weiboId=int.Parse(ds.Tables[0].Rows[0]["weiboId"].ToString());
                }
                                                                                                                                                model.authorName= ds.Tables[0].Rows[0]["authorName"].ToString();

                return model;
            }
            else
            {
                return null;
            }
        }