Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.C
cmd.CommandText = "S ELECT 单位,总付款 from book2 "
dt = cmd.ExecuteReader()
Dim cmd1 As New SQLCommand
Dim dt1 As DataTable
cmd1.C
cmd1.CommandText = "S elect _identify as 序号, 单位,月份,应付款,已付款 from book1 "
dt1 = cmd1.ExecuteReader()
Dim mxzje As Decimal
Dim je As Decimal
Dim sb As new StringBuilder
For Each dr As DataRow In dt.DataRows
Dim drs As List(Of DataRow)
drs = dt1.Select("单位 =\'" & dr("单位") & "\'","月份 asc")
je = dr("总付款")
For Each dra As DataRow In dt1.DataRows
If je>= dra("应付款") Then
sb.AppendLine( " u pdate book1 set 已付款 = " & dra("应付款") & " where _identify = " & dra("序号") )
je = je - dra("应付款")
Else
sb.AppendLine( " u pdate book1 set 已付款 = " & je & " where _identify = " & dra("序号"))
je = 0
End If
Next
Next
cmd.CommandText = sb.ToString`
cmd.ExecuteNonQuery