ASP - using a variable in a Do Loop
|
Original Message
|
Name: johnny
Date: April 30, 2003 at 09:01:43 Pacific
Subject: ASP - using a variable in a Do LoopOS: naCPU/Ram: na |
Comment: I'm using a Do Loop to cycle through a table and compare the value of a variable to the value of one of the fields. Oddly, the comparison works fine if I manually assign the value of the variable (e.g. "ContactKey = 11") but the comparison fails if I use the ContactKey = Request.form("ContactKey") method. *However* (and this is where it gets weird), the ContactKey = Request.Form("ContactKey") is successful at retrieving the value from the previous page. I've verified that this is true by doing a "Response.Write ContactKey" outside of the Do Loop. No problems in that event. This problem is really blowing my mind. Any help would be tremendously appreciated. Here's the code: ContactKey = Request.Form("ContactKey") objRS.MoveFirst Do While not objRS.EOF If objRS.Fields("ContactID") = ContactKey Then varContactName = objRS.Fields("FirstName") & " " & objRS.Fields("LastName") End If objRS.MoveNext Loop Many, many thanks in advance.
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: mitime
Date: May 1, 2003 at 16:29:30 Pacific
|
Reply: (edit)ContactKey = Request.Form("ContactKey") will result in a string variable. objRS.Fields("ContactID") is most likely an interger value. Therefore the string "11" does not equal the interger value 11. Convert your request.form to an integer value using Cint(Request.Form("ContactKey")). (Although you may want to do some checking on the value to make sure it is a numeric value, ie use IsNumeric to see if it is a numeric value before CInt. Good luck Mike
Report Offensive Follow Up For Removal
|
Use following form to reply to current message: