|
-
Nov 27th, 2002, 04:08 PM
#1
Thread Starter
New Member
how can i avoid duplicate values in database
Hi,
I want to insert a record into the database and i want only unique values in my database using ado.
every thing is going fine but i am unable to restrict the duplicate values.How should i write code to avoid duplicate values in my database.
where URL is the field and it should be unique.
My code is :
Private Sub AddRecord()
On Error GoTo ErrorHandler
Dim SavedFlg As Boolean
' Add a new record using the recordset object
' Could be done using the connection object
SavedFlg = True
mRs.Open "SELECT * FROM csecurity", mCn, adOpenKeyset, adLockOptimistic
With mRs
If SavedFlg = True Then
mCn.BeginTrans
.AddNew
.Fields("WINDOWTITLE").Value = TxtIETitle.Text
.Fields("URL").Value = TxtIEUrl.Text
.Fields("ADATE").Value = Now
mRs.Update
mCn.CommitTrans
End If
' After updating the recordset, we need to refresh it, and then move to the
' end to get the newest record. We can then retrieve the new record's id
.Requery
.MoveLast
.Close
End With
ErrorHandler:
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
any one can help me..
Thanks for advance
-
Nov 27th, 2002, 04:14 PM
#2
Frenzied Member
Do you have a Primary Key set?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|