参考,水费自己参考着改。
Dim d As Date = Date.Today
Dim dt As DataTable = DataTables("汇总")
Dim dt1 As DataTable = DataTables("电表")
Dim dt2 As DataTable = DataTables("人员")
Dim dt3 As DataTable = DataTables("单价")
dt.DataRows.clear
For Each fh As String In dt2.GetValues("房号", "入住日期 <= #" & d.AddDays(-15) & "#")
Dim dr1 As DataRow = dt1.find("房号 = '" & fh & "'")
Dim drs2 = dt2.Select("房号 = '" & fh & "'")
For Each dr As DataRow In drs2
Dim ndr As DataRow = dt.addnew
ndr("房号") = fh
ndr("宿舍人员") = dr("姓名")
ndr("性别") = dr("性别")
ndr("部门车间班组") = dr("部门")
ndr("入住日期") = dr("入住日期")
If dr1 IsNot Nothing Then
ndr("栋数及楼层") = dr1("栋数及楼层")
ndr("用量_电量") = dr1("当月使用量")
ndr("金额_电费") = dr1("金额")
End If
ndr("个人承担费用") = ndr("金额_电费") / drs2.count
Next
Next