I am trying to check if a record exist in the database. If it exists discard insert function. And if the record does not exist insert.
I'm getting the opposite effect.
<%
Set OBJdbConnection = Server.CreateObject("ADODB.Connection")
OBJdbConnection.open MM_Listings_STRING
'1. Check if contractor is linked
SQLQuery1 = "Select * FROM Agent_Contractor WHERE ContractorID = " &_
Request.Form("ContractorID") & " AND AgentID = " & Session("AgentID")
Set Results = OBJdbConnection.Execute(SQLQuery1)
'1. If linked response write.
If Results.EOF Then
Response.Write "Contractor Already Linked"
else
'1. Insert
SQLQuery3 = "INSERT INTO Agent_Contractor (" &_
"ContractorID, " &_
"AgentID) VALUES (" &_
Request.Form("ContractorID") & ", " &_
Session("AgentID") & ")"
OBJdbConnection.Execute(SQLQuery3)
Response.Write "Contractor Linked successfully."
end if
%>
ADODB.Command
object to build a Parametrised Query, instead of usingADODB.Connection
'sExecute()
method.Agent_Contractor
table consider usingSELECT NULL FROM Agent_Contractor ...
the query will still work but will not return any field, justNULL
which still signifies the existence of the record without the overhead of usingSELECT *
(Assuming your using SQL Server for your db, not specified in your question or tags).