日期:2014-05-20 浏览次数:20455 次
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace HeavenModels.Models { public class Article { public int ID { get; set; } public int ClassID { get; set; } public string Title { get; set; } public string Author { get; set; } public string CopyFrom { get; set; } public string Keyword { get; set; } public int Hits { get; set; } public DateTime UpdateTime { get; set; } public int OnTop { get; set; } public int Elite { get; set; } public int Status { get; set; } public string Content { get; set; } public string DefaultPicUrl { get; set; } public int Deleted { get; set; } } }
using System; using System.Collections.Generic; using System.Configuration; using System.Data.SqlClient; namespace HeavenModels.Models { public class ArticleDataContext { public static string connectionString = ConfigurationManager.ConnectionStrings["HeavenDB"].ConnectionString; public static string Admin_Article_Add() { ..... } public static IEnumerable<Article> GetArticleList() { List<Article> articles = new List<Article>(); using (SqlConnection connection = new SqlConnection(connectionString)) { string commandText = "select * from He_Article"; using (SqlCommand command = new SqlCommand(commandText, connection)) { connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Article article = new Article(); article.ID = (int)reader["ID"]; article.ClassID = (int)reader["ClassID"]; article.Title = (string)reader["Title"]; article.Author = (string)reader["Author"]; article.CopyFrom = (string)reader["CopyFrom"]; article.Keyword = (string)reader["Keyword"]; article.Hits = (int)reader["Hits"]; article.UpdateTime = (DateTime)reader["UpdateTime"]; article.OnTop = (int)reader["OnTop"]; article.Elite = (int)reader["Elite"]; article.Status = (int)reader["Status"]; article.Content = (string)reader["Content"]; article.DefaultPicUrl = (string)reader["DefaultPicUrl"]; article.Deleted = (int)reader["Deleted"]; articles.Add(article); } connection.Close(); } } return articles; } } }