View Single Post
  #2 (permalink)  
Old 05-12-2008, 10:37 AM
glook glook is offline
Junior Member
 
Join Date: Oct 2007
Location: Berkshire, UK
Posts: 30
Awards Showcase
Beta Tester 
Total Awards: 1
Default

If field1 is set as the PRIMARY KEY or a UNIQUE column, then it will not accept duplicate values. Personally I think it is best practice to test for duplicates before attempting an insert, so that you can nicely control the action. This is easily done with a small select:

cmd.CommandText = "SELECT ROWID from My_table WHERE Name = '" & txtName.Text & "'"
reader.Value = cmd.ExecuteReader
havedup = reader.ReadNextRow
reader.Close
If havedup Then
Msgbox(txtName.Text & " already exists!" & crlf & "Must be unique.",,cMsgBoxHand)
Return
End If


Geoff.
__________________
Geoffrey Looker
www.deeproot.co.uk
Reply With Quote