1、业务实体:
public class Article
{
private int _articleId;
private string _title;
private string _articleDetails;
public int ArticleId
{
get { return _articleId; }
set { _articleId = value; }
}
…
}
2、通用的SQLHelper 方法:
/// <summary>
/// 执¡ä行D有®D参?SQL语®?句?,ê?并¡é返¤¦Ì回?SqlDataReader
/// </summary>
public static SqlDataReader GetReader(string sql, params SqlParameter[] values)
{
SqlCommand cmd = new SqlCommand(sql, Connection);
cmd.Parameters.AddRange(values);
SqlDataReader reader = cmd.ExecuteReader();
return reader;
}
3、数据访问层方法:
数据填充方法:
private static Article FillRecord(SqlDataReader reader)
{
Article a = new Article();
a.ArticleId = Convert.ToInt32(reader["articleId"]);
a.ChannelId = Convert.ToInt32(reader["channelId"]);
a.Title = Convert.ToString(reader["title"]);
a.ArticleDetails = Convert.ToString(reader["articleDetails"]);
return a;
}
数据访问层代码:
public static IList<Article> GetArticleByTitle(string t)
{
IList<Article> articles = new List<Article>();
string sql = "select * from article where title like %@title% order by dateCreated desc";
try
{
using (SqlDataReader reader = SqlHelper.GetReader(sql, new SqlParameter("@title", t)))
{
while (reader.Read())
{
articles.Add(FillRecord(reader));
}
}
return articles;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
5、业务逻辑方法:
public static IList<Article> GetAllArticles()
{
return ArticleService.GetAllArticles();
}
5、页面表现层:
<div>
<ul>
<li> 标题: 日期 </li>
……………………………………………..
</ul>
</div>
6、请问不用ASP.Net的GrewView等控件,如何掉调用 业务逻辑层 .把数据呈现在页面
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
IList<Article> a = new List<Article>();
}
}
如果返回一个IList<Article>,该如何呈现呢 !?
可转以直接在后台拼接HTML字符串
用AJAX怎样实现上传功能
直接在html页面中写代码 <% %>
可以在前台放一个Label,然后在后台动态拼Html的表格,然后Label.Text = 拼得Html表格,这是一种方法
<% %>
然后配合table+css