首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

关于DataGridView数据转换的有关问题

2012-03-23 
关于DataGridView数据转换的问题第一次C#开发,帮朋友做个转换Excel数据格式的小程序,开发存在如下问题,请

关于DataGridView数据转换的问题
第一次C#开发,帮朋友做个转换Excel数据格式的小程序,开发存在如下问题,请高手帮忙解决。
简单描述:
原始表:
序号 经度 纬度 时间
1 88 76
2 89 76
3 90 75

4 77 90
5 78 91
6 79 90
转换成目标表
序号 经度1 纬度1 经度2 纬度2 经度3 纬度3
1 88 76 89 76 90 75
4 77 90 78 91 79 90

数据量每天大概1W左右。

我首先利用OLEDB读取原始记录表,绑定DataGridView,显示出来。然后,想做个按钮,点击开始转换,形成目标表的样子利用DataGridView显示出来,最终点击“导出Excel”按钮,生成新的报表。

思路就是这样的,现在在转换这一步不知道该怎么弄,如果给目标表DataGridView绑定数据源显示。

请高手指点。

[解决办法]

SQL code
--在SQL SERVER 中就是个行转列declare @T table (序号 int,经度 int,纬度 int)insert into @Tselect 1,88,76 union allselect 2,89,76 union allselect 3,90,75 union allselect 4,77,90 union allselect 5,78,91 union allselect 6,79,90select     min(序号) as 序号,    max(case when 序号%3=1 then 经度 else 0 end) as 经度1,    max(case when 序号%3=1 then 纬度 else 0 end) as 纬度1,    max(case when 序号%3=2 then 经度 else 0 end) as 经度2,    max(case when 序号%3=2 then 纬度 else 0 end) as 纬度2,    max(case when 序号%3=0 then 经度 else 0 end) as 经度3,    max(case when 序号%3=0 then 纬度 else 0 end) as 纬度3from @T group by ceiling(序号/3.0)/*序号          经度1         纬度1         经度2         纬度2         经度3         纬度3----------- ----------- ----------- ----------- ----------- ----------- -----------1           88          76          89          76          90          754           77          90          78          91          79          90*/
[解决办法]
转换按钮事件就是换一下数据即可。
SQL code
--转换前的数据select * from tablename--转换后的数据select     min(序号) as 序号,    max(case when 序号%3=1 then 经度 else 0 end) as 经度1,    max(case when 序号%3=1 then 纬度 else 0 end) as 纬度1,    max(case when 序号%3=2 then 经度 else 0 end) as 经度2,    max(case when 序号%3=2 then 纬度 else 0 end) as 纬度2,    max(case when 序号%3=0 then 经度 else 0 end) as 经度3,    max(case when 序号%3=0 then 纬度 else 0 end) as 纬度3from tablename group by ceiling(序号/3.0) 

热点排行