| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 624 人关注过本帖
标题:[求助]数据统计问题!
只看楼主 加入收藏
35maoe
Rank: 1
等 级:新手上路
帖 子:341
专家分:0
注 册:2006-8-28
结帖率:100%
收藏
 问题点数:0 回复次数:4 
[求助]数据统计问题!

图片附件: 游客没有浏览图片的权限,请 登录注册

如上图,红色部分是我想实现的效果,
数据层:
public DataSet EquipAll()
{
try
{
string sql = "select s.id as 编号,p.XZ_Name as 所属派出所,s.bus as 汽车,s.bike as 自行车,s.computer as 计算机,s.saomiaoyi as 扫描仪 from equip as s,paicusu_table as p where p.id=s.paicusu_id";

SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.Fill(ds, "equip");
}
catch (Exception ex)
{

throw ex;
}
return ds;
}
表示层:
this.dataGridView1.DataSource = ds.Tables["equip"].DefaultView;
ds.Tables["equip"].DefaultView.AllowNew = false;//去掉空行
请帮我修改一下要如何实现这种效果,急,谢谢!!

搜索更多相关主题的帖子: 扫描仪 计算机 数据 equip 
2007-11-19 13:51
guoxhvip
Rank: 8Rank: 8
来 自:聖西羅南看臺
等 级:贵宾
威 望:44
帖 子:4052
专家分:135
注 册:2006-10-8
收藏
得分:0 
用DataSet模拟了一个你的表结构,答案就在下面自己看吧
bpKFInlX.rar (30.79 KB) [求助]数据统计问题!



愛生活 && 愛編程
2007-11-20 02:37
35maoe
Rank: 1
等 级:新手上路
帖 子:341
专家分:0
注 册:2006-8-28
收藏
得分:0 
谢谢,搞定,再麻烦一下,如果要生成报表怎么写,没做过报表!!!!

2007-11-20 08:12
guoxhvip
Rank: 8Rank: 8
来 自:聖西羅南看臺
等 级:贵宾
威 望:44
帖 子:4052
专家分:135
注 册:2006-10-8
收藏
得分:0 

用水晶报表吧


愛生活 && 愛編程
2007-11-20 17:08
junxi1
Rank: 1
等 级:新手上路
威 望:1
帖 子:213
专家分:0
注 册:2007-9-17
收藏
得分:0 

转贴guoxhvip的包中的代码,以便有和我一样想看代码的学习:
private void Form1_Load(object sender, EventArgs e)
{
ds = new DataSet();
ds.Tables.Add("policeStation");
ds.Tables["policeStation"].Columns.Add("编号",typeof(string));
ds.Tables["policeStation"].Columns.Add("所属派出所",typeof(string));
ds.Tables["policeStation"].Columns.Add("汽车", typeof(int));
ds.Tables["policeStation"].Columns.Add("自行车", typeof(int));
ds.Tables["policeStation"].Columns.Add("计算机", typeof(int));
ds.Tables["policeStation"].Columns.Add("扫描仪", typeof(int));
ds.Tables["policeStation"].Rows.Add(new object[] {"1","龙头派出所",1,1,1,1});
ds.Tables["policeStation"].Rows.Add(new object[] {"2","新可镇派出所",12,12,12,3});
ds.Tables["policeStation"].Rows.Add(new object[] {"3","贤官镇派出所",12,21,0,0});
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}

private void btnAdd_Click(object sender, EventArgs e)
{
object[] newRow = new object[6];
int[] sum = new int[4];
foreach (DataRow row in ds.Tables[0].Rows)
{
sum[0] += int.Parse(row["汽车"].ToString());
sum[1] += int.Parse(row["自行车"].ToString());
sum[2] += int.Parse(row["计算机"].ToString());
sum[3] += int.Parse(row["扫描仪"].ToString());
}
int i = 0;
newRow[i++] = "";
newRow[i++] = "统计";
newRow[i++] = sum[0];
newRow[i++] = sum[1];
newRow[i++] = sum[2];
newRow[i++] = sum[3];
this.ds.Tables[0].Rows.Add(newRow);
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;

[此贴子已经被作者于2007-11-21 11:53:34编辑过]


foreach( in ){ }
2007-11-21 11:49
快速回复:[求助]数据统计问题!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016035 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved