日期:2014-05-18  浏览次数:20422 次

更新dataset的问题,请各位高手帮帮忙啊!!急!
现在有一个dataset,绑定到datagrid中显示为:
      a             b             c           d
    2006       张三       男           2
    2007       李四       男           3
    2006       张三       男           6
    2006       王五       女           3
    2007       李四       男           4
问题是:怎样修改dataset使得绑定到datagrid中显示为:
      a             b             c           d
    2006       张三       男           8
    2007       李四       男           7
    2006       王五       女           3
即:字段“a”   ,“b”   ,“c”相同的“d”的值相加,且不显示相同行。

部分代码:
myda=new   SqlDataAdapter(strsql,mycon)
ds=new   DataSet();
myda.Fill(ds, "id ");
DataTable   dt=ds.Tables( "id ");
DataGrid1.DataSource=ds.Tables[ "id "].DefaultView;
 


------解决方案--------------------
create table #t
(
a int ,
b varchar(10) ,
c varchar(10) ,
d int
)

insert into #t(a, b ,c , d) values( '2006 ', '张三 ', '男 ', '73 ')
insert into #t(a,b ,c , d) values( '2006 ', '张三 ', '男 ', '83 ')
insert into #t(a,b ,c , d) values( '2006 ', '张三 ', '男 ', '93 ')
insert into #t(a,b ,c , d) values( '2007 ', '李四 ', '女 ', '74 ')
insert into #t(a,b ,c , d) values( '2007 ', '李四 ', '女 ', '83 ')
insert into #t(a,b ,c , d) values( '2007 ', '李四 ', '女 ', '93 ')

drop table #t

select * from #t

select a ,b ,c,sum(d) Count_ from #t group by a ,b,c


---------------------
a b c d
------------------------------
2006 张三 男 249
2007 李四 女 250