Dim d AsDate = e.DataRow("日期") Dim y AsInteger = d.Year Dim m AsInteger = d.Month Dim Days AsInteger = Date.DaysInMonth(y,m) Dim fd As Date = New Date(y,m,1) '获得该月的第一天 Dim ld As Date = New Date(y,m,Days) '获得该月的最后一天 Dim bh AsString = Format(d,"yyyyMM") '生成编号的前6位,4位年,2位月. If e.DataRow("编号").StartsWith(bh) = False'如果编号的前6位不符 Dim max AsString Dim idx AsInteger max = e.DataTable.Compute("Max(编号)","日期 >= #" & fd & "# And 日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")) '取得该月的最大编号