vb 数据库记录添加前判断是否存在相同记录
DimcnAsNewADODB.ConnectionDimRsAsNewADODB.RecordsetDimcnStrAsString,sqlStrAsStringcnS...
Dim cn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Dim cnStr As String, sqlStr As String
cnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\xsxj.mdb;Persist Security Info=False"
sqlStr = "select * from 档案" 'where Uname ='" & Text1.Text & "'"
cn.Open cnStr
Rs.Open sqlStr, cn, adOpenKeyset, adLockOptimistic
Dim i1 As Integer, i2 As Integer
Dim qqNum As String, j As Integer '记录有效QQ号
Dim qqMail As String
Dim i As Integer
For i = 0 To UBound(strArr)
i1 = InStr(1, strArr(i), "(")
If i1 <> 0 Then
i2 = Len(strArr(i)) '总长度
qqNum = Mid$(strArr(i), i1 + 1, i2 - i1 - 1)
If IsNumeric(qqNum) = True Then
qqMail = qqNum & "@qq.com" 'QQ邮箱
Rs.AddNew
Rs.Fields("zh") = 100 + i
Rs.Fields("jie") = QQTitle 'QQ群名称
Rs.Fields("qq") = qqNum
Rs.Fields("mail") = qqNum
Rs.Update
If j <> 0 And j Mod 20 = 0 Then qqStr = qqStr & vbCrLf & vbCrLf
qqStr = qqStr & qqNum & ";"
j = j + 1
If j = 500 Then
'500限制
Exit For
End If
End If
End If
Next
Rs.Close
cn.Close
这段数据库添加记录代码,我想要在添加记录前先判断是否存在相同的记录再添加,判断的条件是"jie"和"QQ"两个字段中存在和刚加进来的相同(两个同时相同),满足此条件则不添加记录 展开
Dim Rs As New ADODB.Recordset
Dim cnStr As String, sqlStr As String
cnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\xsxj.mdb;Persist Security Info=False"
sqlStr = "select * from 档案" 'where Uname ='" & Text1.Text & "'"
cn.Open cnStr
Rs.Open sqlStr, cn, adOpenKeyset, adLockOptimistic
Dim i1 As Integer, i2 As Integer
Dim qqNum As String, j As Integer '记录有效QQ号
Dim qqMail As String
Dim i As Integer
For i = 0 To UBound(strArr)
i1 = InStr(1, strArr(i), "(")
If i1 <> 0 Then
i2 = Len(strArr(i)) '总长度
qqNum = Mid$(strArr(i), i1 + 1, i2 - i1 - 1)
If IsNumeric(qqNum) = True Then
qqMail = qqNum & "@qq.com" 'QQ邮箱
Rs.AddNew
Rs.Fields("zh") = 100 + i
Rs.Fields("jie") = QQTitle 'QQ群名称
Rs.Fields("qq") = qqNum
Rs.Fields("mail") = qqNum
Rs.Update
If j <> 0 And j Mod 20 = 0 Then qqStr = qqStr & vbCrLf & vbCrLf
qqStr = qqStr & qqNum & ";"
j = j + 1
If j = 500 Then
'500限制
Exit For
End If
End If
End If
Next
Rs.Close
cn.Close
这段数据库添加记录代码,我想要在添加记录前先判断是否存在相同的记录再添加,判断的条件是"jie"和"QQ"两个字段中存在和刚加进来的相同(两个同时相同),满足此条件则不添加记录 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询