求助:输入数据库如何判断条目避免重复?
正常可以录入数据,但是遇到相同文本内容的就直接报错退出,现在我参考了一段代码,把它加进来,但是每次添加都报“系统已存在该条记录”,找不出是哪里的原因,请各位帮忙看下了啊!Private Sub cmdOK_Click()
Dim strSQL2 As String
Dim rs As New ADODB.Recordset
If CheckData() = False Then Exit Sub
strSQL2 = "INSERT INTO tb_timecard(timecard_id,employee_id,employee_name,timecard_date,timecard_stime,timecard_xtime,timecard_time) "
strSQL2 = strSQL2 & "VALUES('" & txtTimecardid.Text & "','" ' kq编号
strSQL2 = strSQL2 & cmbEmpid.Text & "','" '员工工号
SQLExt (strSQL2)
MsgBox "添加成功!", vbInformation + vbOKOnly, "提示"
End Sub
Private Function CheckData() As Boolean
strSQL0 = "SELECT * FROM tb_timecard WHERE timecard_id = '" & Trim(txtTimecardid.Text) & " ' AND timecard_date = # " & DTPickerDate.Value & " # "
Set bs = QueryExt(strSQL0)
If bs.RecordCount <> 0 Then
MsgBox ("系统已存在该条记录,请修改后重试!")
CheckData = False
Exit Function
End If
CheckData = True
End Function