Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If statement not working.... 1

Status
Not open for further replies.

alwaysAnewbie

Programmer
Sep 12, 2002
23
US
I have an ASP web page thet I changed to query from one DB to another. The code worked previously. The connection is fine and data is returned but highlighted if is failing:

Code:
<%
company = REQUEST.FORM("company")
response.write "form var =|" & company & "|"

Dim conn, strSQL, rsRes, ConnStr 
Set conn = Server.CreateObject("ADODB.Connection")

ConnStr = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=blah;" & _
          "Password=Blahblah;database=Yeah_right;Data Source=MyServer"

conn.Open ConnStr

set rsRes = Server.CreateObject("ADODB.Recordset")

strSQL="SELECT     OrgCodeIdNo, OrganizationDescription " & _
       "FROM         tORGANIZATIONS " & _
       "WHERE     (OrganizationTypeIdNo = 16) " & _
       "ORDER BY OrganizationTypeIdNo, OrganizationDescription"

Set rsRes = Conn.Execute(strSQL)
Do While Not rsRes.EOF
response.write "SQL var =|" & rsRes("OrgCodeIdNo") & "|"
  Response.write "<option class='normal' value=" & """" & rsRes("OrgCodeIdNo") & """" 

response.write "eval=|" & rsRes("OrgCodeIdNo") = company & "|"

[b]  if rsRes("OrgCodeIdNo") = company then 
   Response.write " selected"
  end if[/b]

  response.write ">" & rsRes("OrganizationDescription") & "</option>"
  rsRes.movenext
loop

rsRes.Close
set rsRes = nothing

Here is the output:
Code:
form var =|277|
SQL var =|275|<option class='normal' value="275"False>Geriatric Care Services</option>
SQL var =|277|<option class='normal' value="277"False>Life Services</option>
SQL var =|280|<option class='normal' value="280"False>Lutheran Senior Life</option>
SQL var =|282|<option class='normal' value="282"False>Passavant Retirement Center</option>
SQL var =|287|<option class='normal' value="287"False>St John Lutheran Care Center</option>

The form var is from the form. The SQL var is what is returned from the DB. The False after the value parameter is the statement evaluation. I have tried the value parameter with and without quotes with no change.

Any ideas?
 
try this:

if rsRes("OrgCodeIdNo") = "company" then
Response.write " selected"
end if

-DNG
 
I tried it but it did not work. I though that would compare the returned value to the literal string company.
 
var is not a value or anything. It is just in the output string I used. At the top you'll notice I loaded the variable company with the form value. The output shows that the value is loaded.
 
sorry my bad...not sure what i was thinking...

you are trying to compare the recordset value with the form value...if that is right them

rsRes("OrgCodeIdNo") = company or

rsRes("OrgCodeIdNo") = request.form("company")

should work fine...

-DNG
 
I assume that rsRes("OrgCodeIdNo") returns an integer. I also assume that Request.Form("company") returns an integer.

If the assumptions are correct, then change the following 2 lines. I suspect that you are getting string compares and one of the values has a leading and/or trailing space.


company = [!]cLng([/!]REQUEST.FORM("company")[!])[/!]

if [!]cLng([/!]rsRes("OrgCodeIdNo")[!])[/!] = company Then



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
The cLng was it. I thought that might be the problem but the DB was an integer and the value parameter in the form had no quotes when I started.

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top