public Themeinfo GetArticleById(int id) { UserSerice us = new UserSerice(); string sql = "SELECT * FROM Theme WHERE Id = @Id"; int ThemeId; SqlDataReader reader = Helper.GetReader(sql, new SqlParameter("@Id", id)); if (reader.Read()) { Themeinfo article = new Themeinfo(); article.Id = (int)reader["Id"]; article.Title = (string)reader["Title"]; article.T_Content = (string)reader["T_Content"]; article.T_PublishTime = (DateTime)reader["T_PublishTime"]; article.Counts = (int)reader["Counts"]; ThemeId = (int)reader["ThemeId"]; //FK reader.Close(); article.Anthor = us.GetUserById(ThemeId); return(article); } else { reader.Close(); return(null); } }
private IList <Themeinfo> GetArticlesBySql(string sql, params SqlParameter[] values) { UserSerice ui = new UserSerice(); List <Themeinfo> list = new List <Themeinfo>(); DataTable table = Helper.GetDataSet(sql, values); foreach (DataRow row in table.Rows) { Themeinfo article = new Themeinfo(); article.Id = (int)row["Id"]; article.Title = (string)row["Title"]; article.T_Content = (string)row["T_Content"]; article.T_PublishTime = (DateTime)row["T_PublishTime"]; article.Spot = (int)row["Spot"]; article.Anthor = ui.GetUserById((int)row["Id"]); //FK list.Add(article); } return(list); }