Inserting into SQL table only if doesn't already exist?
Hi guys,
(Using .net cf 2.0)
I have the following insert statement:
VB Code:
With sqlCmd
.CommandText = "INSERT INTO photos(visitID, photoType, photoLocation, havePhoto)VALUES(@visitID, @photoType, @photoLocation, @havePhoto)"
.Parameters.Add(New SqlCeParameter("@visitID", GetCurrentVisit()))
.Parameters.Add(New SqlCeParameter("@photoLocation", photoLocation))
.Parameters.Add(New SqlCeParameter("@photoType", photoType))
.Parameters.Add(New SqlCeParameter("@havePhoto", "Y"))
.ExecuteNonQuery()
.Parameters.Clear()
End With
But i only want it to do the insert if the value in photoLocation doesn't already exist?
How can i go about doing this?
Thanks in advance for any help
:afrog:
Re: Inserting into SQL table only if doesn't already exist?
You should set up your database to not allow duplicates in the photoLocation field and then it will not accept duplicates, otherwise you will need to query the database based on the values you are trying to enter to see if they exist.
Re: Inserting into SQL table only if doesn't already exist?
Ok thanks for the reply. :thumb:
How do i set up the database not to allow duplicates?
:)
Re: Inserting into SQL table only if doesn't already exist?
What is the database backend? The basic answer is to create a unquie index on the field.