/// <summary> /// 得到一个对象实体 /// </summary> public MZZ.Model.tb_news DataRowToModel(DataRow row) { MZZ.Model.tb_news model=new MZZ.Model.tb_news(); if (row != null) { if(row["news_id"]!=null && row["news_id"].ToString()!="") { model.news_id=int.Parse(row["news_id"].ToString()); } if(row["news_category"]!=null) { model.news_category=row["news_category"].ToString(); } if(row["news_title"]!=null) { model.news_title=row["news_title"].ToString(); } if(row["news_introduce"]!=null) { model.news_introduce=row["news_introduce"].ToString(); } if(row["news_text"]!=null) { model.news_text=row["news_text"].ToString(); } if(row["news_relative_path"]!=null) { model.news_relative_path=row["news_relative_path"].ToString(); } if(row["news_absolute_path"]!=null) { model.news_absolute_path=row["news_absolute_path"].ToString(); } if(row["news_recom"]!=null && row["news_recom"].ToString()!="") { model.news_recom=int.Parse(row["news_recom"].ToString()); } if(row["news_top"]!=null && row["news_top"].ToString()!="") { model.news_top=int.Parse(row["news_top"].ToString()); } if(row["news_time"]!=null && row["news_time"].ToString()!="") { model.news_time=DateTime.Parse(row["news_time"].ToString()); } if(row["news_remarks"]!=null) { model.news_remarks=row["news_remarks"].ToString(); } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public MZZ.Model.tb_news GetModel(int news_id) { StringBuilder strSql=new StringBuilder(); strSql.Append("select news_id,news_category,news_title,news_introduce,news_text,news_relative_path,news_absolute_path,news_recom,news_top,news_time,news_remarks from tb_news "); strSql.Append(" where news_id=@news_id"); MySqlParameter[] parameters = { new MySqlParameter("@news_id", MySqlDbType.Int32) }; parameters[0].Value = news_id; MZZ.Model.tb_news model=new MZZ.Model.tb_news(); DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }