'代码写完整啊,我只是改了和问题有关的一段
Select Case e.DataCol.Name
Case "管辖部门", "开piao月份"
Dim dr As DataRow = e.DataRow
If dr.IsNull("管辖部门") OrElse dr.IsNull("开piao月份") Then
dr("销售数量") = Nothing
Else
Dim m As integer = dr("开piao月份")
Dim y As Integer = Date.Today.Year
Dim dt1 As New Date(y, m, 1)
Dim dt2 As New Date(y, m, Date.DaysInMonth(y, m)) '获取本月的最后一天
Dim Filter As String = "[管辖部门] = '" & dr("管辖部门") & "' and 销售日期 >= #" & dt1 & "# And 销售日期 <= #" & dt2 & "#"
Dim dt As DataTable = DataTables("销售资料")
dr("销售数量") = dt.Compute("Sum(数量)", Filter)
End If
End Select