Results 1 to 2 of 2

Thread: how can i avoid duplicate values in database

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Posts
    15

    Question 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


  2. #2
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    Do you have a Primary Key set?
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width