0
我需要检查数据是否存在,如果数据不存在,那么我将能够插入和更新,但是如果数据存在,那么messagebox将显示数据已经存在但是当我试图添加已经存在的相同数据时,它仍然会添加,并且没有消息框显示它已经存在。检查是否存在或不存在然后插入更新
这里是我的代码
If jobtitle <> "" And businessunit <> "Please Select" And division <> "Please Select" And subdivision <> "Please Select" And classification <> "Please Select" And subclassification <> "Please Select" Then
insrtResult = UpdateInsDelRecord("UPDATE EMP_MASTERTBL SET JOBTITLE = '" & jobtitle & "' " & _
"WHERE MASTERID = '" & empID & "'" & _
";" & _
"INSERT INTO EMPGROUP_TBL(MASTERID, BUSINESS_UNIT, " & _
"DIVISION, SUB_DIVISION, CLASSIFICATION, SUB_CLASSIFICATION) VALUES " & _
"('" & HandleQuote(empID) & "', " & _
"'" & businessunit & "' ," & _
"'" & division & "' ," & _
"'" & subdivision & "' ," & _
"'" & classification & "' ," & _
"'" & subclassification & "')")
If Not insrtResult Then
MessageBox("alert('Error Ocurred While Inserting a Data.')")
Else
MessageBox("alert('Successfully Added.')")
End If
Else
MessageBox("alert('Data Already Exist.')")
End If
可能是什么问题,我的代码?提前致谢。
的[防止重复条目数据库]可能的复制(http://stackoverflow.com/questions/40478342/prevent-duplicate-entries-to-database) – e4c5
'MySQL'或'SQL Server'? – Squirrel
数据是否存在,意味着什么?在数据库中还是在表单中? 在后一种情况下,在您的代码中,如果数据仅存在于数据库中用于一个特定员工,则只需填写一个字段即可,以便插入和更新执行 – Massimo