Code to select a record from an Access DB doesn�

Results 1 to 4 of 4

Thread: Code to select a record from an Access DB doesn�

  1. #1
    Mark Guest

    Default Code to select a record from an Access DB doesn�

    &nbsp;<BR><BR>OK, I&#039;ve only been coding with ASP/VBScript for a couple of weeks, so maybe I&#039;m missing something obvious. The code below is supposed to run through the records in an Access DB until it finds a match based on a unique &#039;ID&#039; number. However, it doesn&#039;t work; I&#039;ve put debugging code in so I can see what&#039;s happening to the variables boardmember and idnum, but they appear to produce correct values. The code after the first if-then statement never executes; the code in the else statement does. Any help would be much appreciated.<BR><BR>&#060;%<BR> Dim con, objRec<BR> strConnect = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:Inetpubwwwrootoardmembers.mdb"<BR> Set con = Server.CreateObject("ADODB.Connection")<BR> con.Open strConnect<BR><BR> <BR><BR> set boardmember = request.querystring("boardmember")<BR><BR> &#039;loop through and display the board member chosen at board_delete.asp<BR> SQL = "SELECT * FROM board"<BR> <BR> set objRec = con.execute(SQL)<BR> <BR> idnum = objRec("IDnum")<BR><BR> While not objRec.EOF<BR> <BR> idnum = objRec("IDnum")<BR><BR> If boardmember = idnum then<BR> <BR> Response.write("&#060;b&#062;Name:&#060;/b&#062; " & objRec("hontitle")& " ")<BR> Response.write(objRec("fname") & " ")<BR> Response.write(objRec("mname") & " ")<BR> Response.write(objRec("lname") & " ")<BR> Response.write(objRec("subtitle") & "<BR>")<BR> Response.write("&#060;b&#062;State:&#060;/b&#062; " & objRec("state") & "<BR>")<BR> Response.write("&#060;b&#062;SGPB title:&#060;/b&#062; " & objRec("sgtitle") & "<BR>")<BR> Response.write("&#060;b&#062;Job title:&#060;/b&#062; " & objRec("jobtitle") & "<BR>")<BR> Response.write("&#060;b&#062;Company:&#060;/b&#062; " & objRec("division") & ", ")<BR> Reponse.write(objRec("company") & "<BR>")<BR> <BR> If objRec("exec") = "x" then<BR> Response.write(",<BR>Executive committee member<BR><BR>")<BR> else<BR> Response.write("<BR><BR>")<BR> end if<BR> &#039;this line is to help me debug this<BR> Response.write("It&#039;s true.<BR>" & idnum)<BR><BR> else<BR> &#039;this is code to help me debug this<BR> Response.write("Record IDnum: " & idnum & "<BR>")<BR> Response.write("Querystring: " & boardmember & "<BR>")<BR> <BR> end if<BR> <BR> objRec.movenext<BR> <BR> Wend<BR><BR> objRec.close<BR> Set objRec = nothing<BR><BR>%&#062;<BR>

  2. #2
    Join Date
    Dec 1969

    Default the difference between objects & vars

    you have set a VARIABLE (boardmember)...see this line:<BR><BR>set boardmember = request.querystring("boardmember")<BR><BR>change it to:<BR><BR>boardmember = request.querystring("boardmember")<BR><BR>you may only set up on it at<BR>hope this helps!!

  3. #3
    Join Date
    Dec 1969
    Los Angeles, CA

    Default Very very bad code

    why select all the records and loop through it. Select ONLY the record you need and do the needful<BR><BR>"SELECT * FROM board where IDnum = " & boardmember <BR><BR>this way you will only get the record you need and not all the other junk that so do not neeed.....and ofcourse you will have to so what ender told you to do<BR><BR><BR>

  4. #4
    Mark Guest

    Default RE: Code to select a record -- thanks

    Changing &#039;set boardmember = request.querystring("boardmember")&#039; to just &#039;boardmember = request.querystring("boardmember")&#039; didn&#039;t seem to make my code work any differently. But the new SQL statement does work, so I&#039;ll go with that.<BR><BR>Mark

Posting Permissions

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