test for matching records to avoid error

Results 1 to 4 of 4

Thread: test for matching records to avoid error

  1. #1
    Rob Guest

    Default test for matching records to avoid error

    Good morning<BR><BR>There is a great article on "Checking if a record exists before adding a new one" at:<BR>http://www.infinitemonkeys.ws/infinitemonkeys/recover.asp?url=/infinitemonkeys/articles/asp/970.asp<BR><BR>I am trying to incorporate this into my code and having problems. Has anyone worked with this that can provide a code snippet of not only the constructed Querystring, but *also* how form the conditional statement (like an if-then) so that if there are records that match, do this, else do that.<BR><BR>My code is below:<BR>myDSN="DSN=oldsadsDSN;uid=sa;pwd="<BR><B R>set conntemp=server.createobject("adodb.connection")<B R>conntemp.open myDSN<BR>form_ID=request.querystring("myID")<BR>fo rm_password=request.querystring("mypassword")<BR>< BR>sqltemp="select * from ads "<BR>sqltemp=sqltemp & " where AdID=&#039;" & form_ID <BR>sqltemp=sqltemp & "&#039; AND AdPassword=&#039;" & form_password & "&#039;"<BR><BR>set rstemp=conntemp.execute(sqltemp)<BR><BR>&#039;If no records match, I dont want the below to occur!<BR>form_AdType=rstemp("AdType")<BR>form_AdM odel=rstemp("AdModel")<BR>form_AdPartCategory=rste mp("AdPartCategory")<BR>form_AdYear=rstemp("AdYear ")<BR>form_AdText=rstemp("AdText")<BR>form_AdURL=r stemp("AdURL")<BR>form_AdPrice=rstemp("AdPrice")<B R>form_AdName=rstemp("AdName")<BR>form_AdEmail=rst emp("AdEmail")<BR>form_AdCity=rstemp("AdCity")<BR> form_AdState=rstemp("AdState")<BR>form_AdZip=rstem p("AdZip")<BR>form_AdPhone=rstemp("AdPhone")<BR>fo rm_AdPassword=rstemp("AdPassword")<BR>form_AdConfi rmPassword=rstemp("AdConfirmPassword")<BR>form_AdD ate=rstemp("AdDate")<BR>form_AdID=rstemp("AdID")<B R><BR>rstemp.close<BR>set rstemp=nothing<BR>conntemp.close<BR>set conntemp=nothing<BR><BR>Any suggestions or examples I can view?<BR>Thanks!<BR>Rob

  2. #2
    Linda Pyrc Guest

    Default RE: test for matching records to avoid error

    simply:<BR><BR>if rstemp.eof &#039;then no matched found <BR> add your record<BR>end if<BR>close etc

  3. #3
    Rob Guest

    Default RE: test for matching records to avoid error

    Thanks for the information. What would be the syntax for "not equal to" <BR><BR>Maybe:<BR>if !rstemp.eof &#039;then no matched found <BR> add your record <BR>end if <BR><BR>What about else and then?<BR><BR>if !rstemp.eof &#039;do I use a then or not?<BR> add your record <BR>else<BR> do something else<BR>end if <BR><BR>Thanks!<BR>Rob

  4. #4
    Linda Pyrc Guest

    Default RE: test for matching records to avoid error

    if not rstemp.eof then<BR> process records ....<BR>else<BR> do something else if required....<BR>end if

Posting Permissions

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