老师,我这个余额的做成这样,可以正常运行,您帮忙看下,是否可有优化或者更高效的办法:此主题相关图片如下:微信截图_20190920172642.png
Dim cmd As new sqlcommand
cmd.c
'Dim r As DataRow = e.DataRow 之前写在 表事件 beforesave,现在改成写在服务器处理,改成for each
cmd.CommandText = "selec t * from 资金日报账户表 where 日期 = '2019-01-01'"
Dim t As DataTable = cmd.ExecuteReader
For Each r As DataRow In t.DataRows
cmd.CommandText = "Selec t * From {资金日报账户表} where 日期 > '" & r("日期") & "'" & _
" And 分销商 = '" & r("分销商") & "' And 类型 = '" & r("类型") & "' and 项目 = '" & r("项目") & "' order by 日期"
Dim dt As DataTable = cmd.ExecuteReader(True)
Dim i As Integer = 0
For Each dr As DataRow In dt.Selec t("","日期")
output.show(i & ": 日期1: " & dr("日期") & " 日期2: " & r("日期"))
If i = 0 Then
dr("上日余额") = r("本日余额")
dr("本日余额") = r("本日余额")+dr("本日增加")-dr("本日减少")
Else
dr("上日余额") = dt.Selec t("","日期")(i-1)("本日余额")
dr("本日余额") = dt.Selec t("","日期")(i-1)("本日余额")+dr("本日增加")-dr("本日减少")
End If
i +=1
Next
dt.save
Next
[此贴子已经被作者于2019/9/20 17:32:38编辑过]