日期:2014-05-17  浏览次数:20420 次

一个新闻显示总条数的问题。
我有两张表,A新闻表,B评论表。我现在把新闻表的内容查询出来了,但是还差一个评论条数。我把数据放在asp:Repeater里面的                
//查询全部圈层新闻                
DataSet ds = new DataSet();                
DataSet ds2 = new DataSet();                
int SpNewId = 0;                
ds = SpheresNewsInfoBLL.AdminSpheresNewsInfoAll();                
for (int i = 0; i < ds.Tables["SpheresNewsInfoAll"].Rows.Count;i++ )                {                    
//SpNewId = (int)row["SptypeId"];                    
SpNewId = (int)ds.Tables["SpheresNewsInfoAll"].Rows[i]["SptypeId"];                    
ds2 = SpheresNewsInfoBLL.AdminSpNewsReviewsinfo(SpNewId);                
}                
myRepeter.DataSource = ds.Tables["SpheresNewsInfoAll"];                myRepeter.DataBind();
新闻条数也查询出来了。但是这个思路肯定是不对的。我要怎么把评论总条数显示在myRepeter下面呢?

------解决方案--------------------
select count(*) from 评论表 where 新闻id=当前新闻id
用sqlCmd.ExecuteScalar()调用
------解决方案--------------------
你的NewsInfoAll是所有新闻吧,你是不是想在每一个新闻后面加个品论数啊

select *  ,p.rows
from newstable
left join(
select count(*)as rows
from 评论 group id
) as p on newid = id