url重写 下次开发一定这么搞,呵呵
博客园的那个月份的 应该是如下存储过程的思维
ALTER proc [dbo].[GetMonthCount]
(
@userId int --用户ID号 根据username获取
)
as
begin
SELECT month([createdate]) as month , year([createdate]) as year
,count([content_id]) as count
FROM [ForeTechTest].[dbo].[blog_content]
where User_id=@userId
group by year([createdate]),month([createdate])
order by year([createdate]) desc ,month([createdate]) desc
end
操作结果如下:
aspx页面
<div>
<%=TableTime() %>
</div>
cs页面:
public string TableTime()
{
try
{
System.Data.SqlClient.SqlParameter para = new System.Data.SqlClient.SqlParameter("@userId",2);//为了简单起见
DataSet ds = DBTool.ExecuteDataset(System.Data.CommandType.StoredProcedure, "GetMonthCount", para);
string UID = "JASENKIN";//为了简单 设置此值
string Year, Month;
StringBuilder sb = new StringBuilder();
sb.Append("<ul>");
if(ds!=null&&ds.Tables[0].Rows.Count>0){
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Year = ds.Tables[0].Rows[i]["year"].ToString();
Month = ds.Tables[0].Rows[i]["month"].ToString();
sb.Append("<li><a href=/Blog/" + UID + "/" + Year + "/" + Month + "/index.aspx" + ">");
sb.Append(Year + "年" + Month + "月");
sb.Append("("+ds.Tables[0].Rows[i]["count"].ToString()+")");
sb.Append("</a></li>");
}
}
sb.Append("</ul>");
return sb.ToString();
}
catch
{
return "";
}
}
测试结果
*********************************