单统计累计,外部数据加载进来用下面内部表代码就弹窗,老师帮忙看看,谢谢
此主题相关图片如下:错误弹窗.png
Select Case e.DataCol.Name
Case "生产批号", "实际产量"
Dim dr As DataRow
Dim mr As DataRow = e.DataRow
Dim drs As List(Of DataRow)
dr = e.DataTable.Find("[_SortKey]< " & mr("_SortKey") & " And [生产批号] = '" & mr("生产批号") & "'", "[_SortKey] Desc")
If dr Is Nothing Then
mr("累计产量") = mr("实际产量") + mr("累计产量")
dr = mr
End If
drs = e.DataTable.Select("[_SortKey]>= " & dr("_SortKey") & " And [生产批号] = '" & dr("生产批号") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("累计产量") = drs(i - 1)("累计产量") + drs(i)("实际产量")
Next
If e.DataCol.Name = "生产批号" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
dr = e.DataTable.Find("[_SortKey]< " & mr("_SortKey") & " And [生产批号] = '" & e.OldValue & "'", "[_SortKey] Desc")
If dr Is Nothing Then
dr = e.DataTable.Find("[生产批号]= '" & e.OldValue & "'", "[_SortKey]")
If dr IsNot Nothing Then
dr("累计产量") = dr("实际产量") + dr("累计产量")
End If
End If
If dr IsNot Nothing Then
drs = e.DataTable.Select("[_SortKey]>= " & dr("_SortKey") & " And [生产批号] = '" & dr("生产批号") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("累计产量") = drs(i - 1)("累计产量") + drs(i)("实际产量")
Next
End If
End If
End Select
这个表的主键是什么?不是_identify?也不是自增列?
代码里不要使用[_SortKey]列了,改为【id编号】列
主键请使用_identify,不要使用_SortKey。_SortKey是排序用的,用作其它用途可能会有冲突