/// <summary> /// 绑定数据 /// </summary> private void BindData() { string sqlsearch = "select * from Article where contentid =" + acNo; dt = conn.ExecuteDataTable(sqlsearch); if (dt != null) { article.setTxt(dt.Rows[0]["txt"].ToString()); article.setDescription(dt.Rows[0]["description"].ToString()); article.setReleaseDate(dt.Rows[0]["releaseDate"].ToString()); article.setUser(dt.Rows[0]["user"].ToString()); } sqlsearch = "select * from user where userid =" + article.getUser(); dt = conn.ExecuteDataTable(sqlsearch); if (dt != null) { user.setlocalavatar(dt.Rows[0]["localavatar"].ToString()); user.setName(dt.Rows[0]["username"].ToString()); user.setSign(dt.Rows[0]["sign"].ToString()); } }
/// <summary> /// 保存文章到数据库 /// </summary> /// <param name="article"></param> /// <returns></returns> public bool SaveArticle(Article.Model.Article article) { string sql = "select * from Article where contentId =" + article.getContentId(); dt = conn.ExecuteDataTable(sql); if (dt.Rows.Count == 0) { string sqlInsert = "INSERT INTO 'Article' ('user', 'txt', 'description', 'contentId', 'isArticle', 'channelId', 'releaseDate', 'title', 'isRecommend', 'views', 'comments', 'stows', 'toplevel', 'cover', 'viewOnly') VALUES ('" + article.getUser() + "', '" + article.getTxt() + "', '" + article.getDescription() + "', '" + article.getContentId() + "', '" + article.getIsArticle() + "', '" + article.getChannelId() + "', '" + article.getReleaseDate() + "', '" + article.getTitle() + "', '" + article.getIsRecommend() + "', '" + article.getViews() + "', '" + article.getComments() + "', '" + article .getStows() + "', '" + article.getToplevel() + "', '" + article.getCover() + "', '" + article.getViewOnly() + "');"; conn.ExecuteScalar(sqlInsert); } return(true); }