Beispiel #1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Pan.Model.News DataRowToModel(DataRow row)
        {
            Pan.Model.News model = new Pan.Model.News();
            if (row != null)
            {

                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (row["title"] != null)
                {
                    model.title = row["title"].ToString();
                }
                try
                {
                    if (row["summary"] != null)
                    {
                        model.summary = row["summary"].ToString();
                    }
                }
                catch { }
                    if (row["isTop"] != null)
                    {
                        model.isTop = row["isTop"].ToString();
                    }
                    if (row["isReco"] != null)
                    {
                        model.isReco = row["isReco"].ToString();
                    }
                    if (row["type"] != null)
                    {
                        model.type = row["type"].ToString();
                    }
                try
                {
                    if (row["content"] != null)
                    {
                        model.content = row["content"].ToString();
                    }

                    if (row["author"] != null)
                    {
                        model.author = row["author"].ToString();
                    }
                    if (row["source"] != null)
                    {
                        model.source = row["source"].ToString();
                    }
                    if (row["views"] != null)
                    {
                        model.views = row["views"].ToString();
                    }
                    if (row["keywords"] != null)
                    {
                        model.keywords = row["keywords"].ToString();
                    }
                    if (row["description"] != null)
                    {
                        model.description = row["description"].ToString();
                    }
                }
                catch { }
                    if (row["time"] != null)
                    {
                        model.time = row["time"].ToString();
                    }

            }
            return model;
        }
Beispiel #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Pan.Model.News GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,title,summary,isTop,isReco,type,content,author,source,views,keywords,description,time from News ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int,4)
            };
            parameters[0].Value = id;

            Pan.Model.News model = new Pan.Model.News();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }