已解决:把e.datarow换成drs(i)
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [科目] ='" & mr("科目") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1 '重算余下行的余额
If drs(i-1)("借或贷")="贷" Then
Dim s As Double = drs(i-1)("余额") - drs(i)("借方") + drs(i)("贷方")
If s>0 Then
drs(i)("余额") = s
drs(i)("借或贷")="贷"
ElseIf s < 0 Then
drs(i)("余额") = -s
drs(i)("借或贷")="借"
ElseIf s = 0 Then
drs(i)("余额") = 0
drs(i)("借或贷")="平"
End If
ElseIf drs(i-1)("借或贷")="借" Then
Dim s1 As Double = drs(i-1)("余额") + drs(i)("借方") - drs(i)("贷方")
If s1>0 Then
drs(i)("余额") = s1
drs(i)("借或贷")="借"
ElseIf s1< 0 Then
drs(i)("余额") = -s1
drs(i)("借或贷")="贷"
ElseIf s1= 0 Then
drs(i)("余额") = 0
drs(i)("借或贷")="平"
End If
ElseIf drs(i-1)("借或贷")="平" Then
If e.DataRow("借方")>0 Then
drs(i)("余额") = e.DataRow("借方")
drs(i)("借或贷")="借"
ElseIf e.DataRow("贷方")>0 Then
drs(i)("余额") = e.DataRow("贷方")
drs(i)("借或贷")="贷"
Else
drs(i)("余额") = 0
drs(i)("借或贷")="平"
End If
End If
Next
[此贴子已经被作者于2011-6-29 9:15:33编辑过]