以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]如何分页显示经过分组统计的表格 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=147701) |
-- 作者:huangfanzi -- 发布时间:2020/3/22 12:59:00 -- [求助]如何分页显示经过分组统计的表格 有张发货表,上面有录入时间,工程名称,发货量,现在有了分组统计,也就是加入了“GROUP BY 工程名称”后,不知如何编写了,例如获取总行数,就怎么改也改不成 Dim cmd As New SQLCommand cmd.C \'记得设置数据源名称 cmd.C ommandText = "S elect 工程名称,sum(发货量) From {销售出库} where " & flt & " GROUP BY 工程名称" cmd.C ommandText = "S elect count(*) from(" & cmd.CommandText & ")" Dim Count As Integer = cmd.ExecuteScalar() \'获取总的行数 下面是一段完整的代码,没有分组统计时使用的,请老师帮我改下,改成按工程名称分组统计发货量并且要分页显示,万分感谢! 。。。上面全是flt的合成 \'获取要显示的页码 Dim page As Integer = 0 \'默认page为0,显示第一页 Dim pageRows As Integer = 10 \'每页10行 If e.GetValues.ContainsKey("page") Then \'如果地址中有page参数 Integer.TryParse(e.GetValues("page"), page) \'提取page参数 End If Dim StartRow As Integer = page * pageRows + 1 \'此页第一行 Dim EndRow As Integer = (page + 1) * pageRows \'此页最后一行 \'提取此页数据 Dim cmd As New SQLCommand cmd.C \'记得设置数据源名称 cmd.C ommandText = "S elect Count(*) From {销售出库}" If flt > "" Then cmd.C ommandText = cmd.C ommandText & " where " & flt End If Dim Count As Integer = cmd.ExecuteScalar() \'获取总的行数 cmd.C ommandText = "S elect * From (S elect Row_Number() Over(Order by 录入时间) As 序号,工程名称,发货量 From {销售出库} " If flt > "" Then cmd.C ommandText = cmd.C ommandText & " where " & flt End If cmd.C ommandText = cmd.C ommandText & ") As a " cmd.C ommandText = cmd.C ommandText & " Where 序号>= " & StartRow & " And 序号 <= " & EndRow Dim dt As DataTable = cmd.ExecuteReader \'获取该页数据 \'根据此页数据生成网页 With wb.AddTable("","Table1") .CreateFromDataTable(dt) End With
[此贴子已经被作者于2020/3/22 13:02:33编辑过]
|
-- 作者:有点蓝 -- 发布时间:2020/3/22 22:05:00 -- dim sql as string = "S elect 工程名称,sum(发货量) as 发货量 From {销售出库} where " & flt & " GROUP BY 工程名称" Dim cmd As New SQLCommand cmd.C \'记得设置数据源名称 cmd.C ommandText = "S elect count(*) from (" & sql& ") as a" Dim Count As Integer = cmd.ExecuteScalar() \'获取总的行数 cmd.C ommandText = "S elect * From (S elect Row_Number() Over(Order by 工程名称) As 序号,工程名称,发货量 From (" & sql & ") as b ) as a where 序号>= " & StartRow & " And 序号 <= " & EndRow [此贴子已经被作者于2020/3/22 22:05:57编辑过]
|