Foxtable(狐表)用户栏目专家坐堂 → [求助][推荐]


  共有5097人关注过本帖树形打印复制链接

主题:[求助][推荐]

帅哥哟,离线,有人找我吗?
leoli
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:301 积分:2547 威望:0 精华:0 注册:2018/11/15 12:35:00
[求助][推荐]  发帖心情 Post By:2022/3/25 22:28:00 [只看该作者]

老师,如截图,可以优化一下代码,使其下载资料后,将列partno相同,在同一个月内的的iquantity 相加,加到表 rdrecords11中。谢谢。

Dim cmd As New SQLCommand
Dim dt As DataTable
DataTables("rdrecords11").datarows.clear
cmd.C 
Dim Cols111() As String = {"cInvcode","iquantity","Dvdate"}
Dim Cols222() As String = {"PartNo","Qty","Date"}
cmd.CommandText ="Se/lect cInvcode,iquantity,dvdate From {rdrecords11} Where [dvDate] > = '" & e.Form.Controls("Datetimepicker1").Value & "' And [dvDate] < = '" & e.Form.Controls("Datetimepicker2").Value & "'"
dt = cmd.ExecuteReader()
For Each dr1 As DataRow In dt.DataRows
    Dim dr2 As DataRow = DataTables("rdrecords11").AddNew()
    For i As Integer = 0 To Cols111.Length -1
        dr2(Cols222(i)) = dr1(Cols111(i))
    Next
Next

图片点击可在新窗口打开查看



 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:111414 积分:567140 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2022/3/26 9:38:00 [只看该作者]

Dim cmd As New SQLCommand
Dim dt As DataTable
DataTables("rdrecords11").datarows.clear
cmd.C
Dim Cols111() As String = {"cInvcode","iquantity"}
Dim Cols222() As String = {"PartNo","Qty"}
cmd.CommandText ="select cInvcode,年,月,sum(iquantity) as iquantity from (Select cInvcode,iquantity,year(dvdate) as 年,month(dvdate) as 月 From {rdrecords11} Where [dvDate] > = '" & e.Form.Controls("Datetimepicker1").Value & "' And [dvDate] < = '" & e.Form.Controls("Datetimepicker2").Value & "') as a group by cInvcode,年,月"
dt = cmd.ExecuteReader()
For Each dr1 As DataRow In dt.DataRows
    Dim dr2 As DataRow = DataTables("rdrecords11").AddNew()
    For i As Integer = 0 To Cols111.Length -1
        dr2(Cols222(i)) = dr1(Cols111(i))
    Next
    dr2("date") = new Date(dr1("年"),dr1("月"),1)
Next

 回到顶部