原创 统计文章表中各类别的文章数收藏

后台:

protected void Page_Load(object sender, EventArgs e)
    {
        DataSet ds;
        OleDbDataAdapter dr;
        DataColumn wenzhangtype;

        //Grab the Categories and Products table
        ds = new DataSet();
        string strDBPath = System.Configuration.ConfigurationSettings.AppSettings["DBPath"];
        string strConn = System.Configuration.ConfigurationSettings.AppSettings["Connection"] + Server.MapPath(strDBPath);
        OleDbConnection myConnection = new OleDbConnection(strConn);

        dr = new OleDbDataAdapter("Select * From ArticleType", myConnection);
        myConnection.Open();
        dr.Fill(ds, "ArticleType");
        dr.SelectCommand = new OleDbCommand("Select * From Article", myConnection);
        dr.Fill(ds, "Article");
        myConnection.Close();

        //Add Parent/Child Relationship
        ds.Relations.Add("catprods", ds.Tables["ArticleType"].Columns["typeid"], ds.Tables["Article"].Columns["typeid"]);

        //Add the aggregate column
        wenzhangtype = new DataColumn(("文章数"), System.Type.GetType("System.Decimal"));
        wenzhangtype.Expression = "Count( Child.NewsID )";
        ds.Tables["ArticleType"].Columns.Add(wenzhangtype);

        //Bind to the DataGrid
        DataGrid1.DataSource = ds;
        DataGrid1.DataMember = "ArticleType";
        DataGrid1.DataBind();

    }

前台:

<asp:DataGrid
  ID="DataGrid1"
  Runat="Server" /> 

发表于 @ 2007年02月26日 09:40:00|评论(loading...)

新一篇: RowFilter的使用..... | 旧一篇: 文章大类控制小类的asp.net代码,dataset过滤缓存...

用户操作
[即时聊天] [发私信] [加为好友]
PConline
订阅我的博客
XML聚合  FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
文章分类
收藏
    存档
    软件项目交易
    Csdn Blog version 3.1a
    Copyright © PConline