怎么实现数据在新增前先进行有无记录判断,如果有 及更新 如果无就新增……
当前运行效果:红色部分代码如果取消注释 直接不新增数据,如果注释掉,会一直新增数据
想实现:当干部年度考核表中 不存在姓名时,直接新增,如果存在姓名时,直接更新对应的数据
当前代码如下:【烦请老师们指导下,在能够实现上述预期功能的前提下,并看看这个代码如何简化一些】
Dim cmd As New SQ L Command
cmd.Connect ion Name = "主数据源"
Dim dt,dt1,dt2,dt3 As DataTable
cmd.CommandText = "SEL ECT * From {干部台账}"
dt = cmd.ExecuteReader()
cmd.CommandText = "SEL ECT * From {干部年度考核}"
dt1 = cmd.ExecuteReader(True)
cmd.CommandText = "SEL ECT * From {干部平时考核登记表}"
dt2 = cmd.ExecuteReader()
cmd.CommandText = "SEL ECT * From {干部培训台账}"
dt3 = cmd.ExecuteReader()
Dim Products As List(Of String)
Products = dt.GetValues("考核类型","考核类型<>''")
For Each Product As String In Products
Output.Show(Product)
Dim Products1 As List(Of String())
Products1 = dt.GetValues("姓名|职务|职级|性别|出生年月|入党时间|任现职时间|从事或分管工作","考核类型='"& Product &"' and 职级 like '%员%'")
For Each Product1 As String() In Products1
Output.Show(Product1(0)&Product1(1)&Product1(2))
Dim dr As DataRow
dr=dt.SQLFind("姓名='"& Product1(0)&"'")
output.show(dr("姓名"))
If dr IsNot Nothing Then
'Else
dr =dt1.AddNew
dr("年度")="2022"
dr("guid")=System.Guid.NewGuid().ToString()
dr("姓名")=Product1(0)
dr("单位及职务")=Product1(1)
dr("职级")=Product1(2)
dr("性别")=Product1(3)
dr("出生年月")=Product1(4)
If Product1(5)<> "" Then
dr("政治面貌")="中共党员"
End If
dr("任现职时间")=Product1(6)
dr("从事或分管工作")=Product1(7)
Dim Products3 As List(Of String())
Products3 = dt1.GetValues("姓名|年度","姓名='"& Product1(0) &"' and 年度<>'' ")
For Each Product3 As String() In Products3
'Output.Show(Product3(0) & Product3(1) )
Dim Products2 As List(Of String())
Products2 = dt2.GetValues("姓名|年份|季度|考核结果","姓名='"& Product3(0) &"' and 年份='"& Product3(1) &"' ")
For Each Product2 As String() In Products2
dr("平时考核结果") &=Product2(1) & "年" & Product2(2) & "季度考核结果为" & Product2(3) & ";"
'Output.Show(dr("平时考核结果"))
Next
Dim Products4 As List(Of String())
Products4 = dt3.GetValues("姓名|培训开始日期|培训结束日期|培训主办单位|培训内容","姓名='"& Product3(0) &"' and 年份='"& Product3(1) &"' ")
For Each Product4 As String() In Products4
dr("参加脱产培训情况") &=Product4(1) & "至" & Product4(2) & "参加由" & Product4(3) & "举办的" & Product4(4) & ";"
'Output.Show(dr("参加脱产培训情况"))
Next
Next
dr.save
End If
Next
Next