加一个是否为空的判断就行了。
Select Case e.DataCol.Name Case "编号" Dim dt As DataTable = DataTables("表B") Dim names() As String = {"张三", "李四", "王五", "薛六"} Dim dr As DataRow = DataTables("表C").Find("编号 = '" & e.NewValue & "'") If dr Is Nothing Then dr = DataTables("表C").AddNew dr("编号") = e.NewValue dr("入库时间") = dt.Compute("Max(入库时间)", "编号 = '" & e.NewValue & "'") dr("查询时间") = dt.Compute("Max(查询时间)", "编号 = '" & e.NewValue & "'") For Each name As String In names If dt.Find("入库人 = '" & name & "' And 编号 = '" & e.NewValue & "'") IsNot Nothing Then dr("入库人") = name Exit For End If Next Case "入库时间", "查询时间" Dim dt As DataTable = DataTables("表B") Dim fdr As DataRow = DataTables("表C").Find("编号 = '" & e.DataRow("编号") & "'") If e.DataRow.IsNull(e.DataCol.Name) Then fdr(e.DataCol.Name) = dt.Compute("Max(" & e.DataCol.Name & ")", "编号 = '" & e.DataRow("编号") & "'") Else Dim dr As DataRow = dt.Find("编号 = '" & e.DataRow("编号") & "' And " & e.DataCol.Name & " > '" & e.NewValue & "'") If dr Is Nothing Then fdr(e.DataCol.Name) = e.NewValue End If End If Case "入库人" Dim names() As String = {"张三", "李四", "王五", "薛六"} Dim dt As DataTable = DataTables("表C") Dim fdr As DataRow = dt.Find("编号 = '" & e.DataRow("编号") & "'") For Each name As String In names If DataTables("表B").Find("入库人 = '" & name & "' And 编号 = '" & e.DataRow("编号") & "'") IsNot Nothing Then fdr("入库人") = name Exit For End If Next End Select
|