Dim dt As DataTable = DataTables("表A") Dim ndr As DataRow = dt.addnew Dim max As String Dim idx As Integer max = dt.Compute("Max(公司编号)"," [_Identify] <> " & ndr("_Identify")) '取得最大编号 If max > "" Then '如果存在最大单据编号 idx = CInt(max.Substring(1,4)) + 1 '获得最大单据编号的后四位顺序号,并加1 Else idx = 1 '否则顺序号等于1 End If ndr("公司编号") = "C" & Format(idx,"0000")