DataColChanged代码
'Dim cmd As New SQLCommand '后台附值
'cmd.C
'cmd.CommandText ="s elect * from {XM_在建项目}"
'Dim dt As DataTable=cmd.ExecuteReader(True)
If e.DataCol.Name = "中标日期" Then
If e.DataRow.IsNull("中标日期") Then
e.DataRow("档案编号") = Nothing
e.DataRow("年份") = Nothing '如果为空,则清除
Else
e.DataRow("年份") = Format(e.DataRow("中标日期"),"yyyy")
Dim bh As String = "P" & Format(e.DataRow("中标日期"),"yy") '取得编号的8位前缀
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(档案编号)","档案编号 like '" & bh & "%' And [_Identify] <> " & e.DataRow("_Identify")) '取得该天的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(bh.length)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("档案编号") = bh & Format(idx,"000")
End If
End If
SQL表,只有加载了全部数据,红色代码才有效 能不能用后台数据“中标日期”列直接生成编号