PDA

Click to See Complete Forum and Search --> : If statements


Randhart
Feb 7th, 2001, 11:26 PM
Hey guy's

I'm trying to compare a string sent by the User to data stored in the DB. Now when I send the results and stuff over I get the No Match found Statement that's in the Else statement .. and I know for a fact that the strings I'm comapring are in the Tables.

Now if i send strings over that doesn't exist in the table I get a Exeption Error Occured on Line 26 .. line 26 is the IF ***** Then line.

Here's my code

***************

Set rsResults = conn.Execute("SELECT Comp_PWD FROM Company WHERE Comp_UID = '" & UserName & "'")

if rsResults("Comp_PWD") = Request.Querystring("sPWD") Then
Response.Write "UserID and Password Matches"
else
Response.Write "No matching Results"
end IF

*****************

Thanks in advance

Feb 7th, 2001, 11:34 PM
Try changing rsResults("Comp_PWD") to read rsResults.fields("Comp_PWD")

Feb 7th, 2001, 11:35 PM
hi....try this

Set rsResults = conn.Execute("SELECT Comp_PWD FROM Company WHERE Comp_UID = '" & UserName & "'")

if Not rsResults.EOF then

if rsResults("Comp_PWD") = Request.Querystring("sPWD") Then
Response.Write "UserID and Password Matches"
rsResults.MoveNext
end IF

else
Response.Write "No matching Results"
end if


Regards,
:o Mac :)

Randhart
Feb 7th, 2001, 11:52 PM
Hey Mad worm .. yours gave the same results.

Mac.L Your atleast changed the results to .. Nothing .. seriously .. it didn't return even the No Matches found.

Here's my Complete code:

************

Dim conn
Dim rsResults
Dim UserName
Dim PWD
Dim aConnect

UserName = Request.Querystring("sUID")
PWD = Request.Querystring("sPWD")
aConnect = "Provider=SQLOLEDB.1;Persist Security Info=False;Data Source=DEV-SVR;Initial Catalog=Alchemy;User ID=Guest;Password=;ConnectionTimeout=10;"

Set conn = Server.CreateObject("ADODB.Connection")
Set rsResults = Server.CreateObject ("ADODB.Recordset")
conn.Mode = abModeReadWrite
conn.ConnectionString = aConnect
conn.open

Set rsResults = conn.Execute("SELECT Comp_PWD FROM Company WHERE Comp_UID = '" & UserName & "'")

if rsResults.fields("Comp_PWD") = Request.Querystring("sPWD") Then
Response.Write "UserID and Password Matches"
else
Response.Write "No matching Results"
end IF

'L Set rsResults = conn.Execute("SELECT Comp_PWD FROM Company WHERE Comp_UID = '" & UserName & "'")

'L if Not rsResults.EOF then
'L if rsResults("Comp_PWD") = Request.Querystring("sPWD") Then
'L Response.Write "UserID and Password Matches"
'L rsResults.MoveNext
'L end if
'L else
'L Response.Write "No matching Results"
'L end if

rsResults.Close
conn.Close


*****
Thanks for your help!

Feb 8th, 2001, 12:27 AM
Hi...

Set rsResults = conn.Execute("SELECT Comp_PWD FROM Company WHERE Comp_UID = '" & UserName & "'")

You SQL statement seem just select one field,

try this,

Set rsResults = conn.Execute("SELECT * FROM Company WHERE Comp_UID = '" & UserName & "'")



Regards,
:o Mac :)

Randhart
Feb 8th, 2001, 12:46 AM
Hey there Mac L. thanks for your help!

I tried what you said but it didn't work .. then i thought baybee the Recordset was empty .. So I made it to write:
**
Response.Write rsResults("Comp_PWD") & "<br>"
Response.Write Request.Querystring("sPWD") & "<br>"
**

I get the same result .. the Comp_PWD and the Querystring value match .. so it's supposed to work ... I seems to me that the fault is somewhere in the If statement .. the select statement with the Wildcard * is usefull because I need the check the Username as well as the PWD.

I'm going to try some diffrent flavours of If Statements .. maybe it will work out some where .. but your help will b apreciated!

Cheers
and Thanks

Randhart
Feb 8th, 2001, 01:51 AM
Ok I'm desparate!

Here's the code:
**************

<%
Dim conn 'Connection
Dim rsResults 'Record Set
Dim aConnect 'Connection String
dim i 'Testing

i = 2 'Testing Value

aConnect = "Provider=SQLOLEDB.1;Persist Security Info=False;Data Source=DEV-SVR;Initial Catalog=Alchemy;User ID=Guest;Password=;ConnectionTimeout=10;"

Set conn = Server.CreateObject("ADODB.Connection")
Set rsResults = Server.CreateObject ("ADODB.Recordset")
conn.Mode = abModeReadWrite
conn.ConnectionString = aConnect
conn.open

Set rsResults = conn.Execute("SELECT * FROM Company WHERE Comp_UID = '" & Request.Querystring("sUID") & "'")

' get value of Record set
Response.Write "RecordSet <br>"
Response.Write rsResults("Comp_PWD") & "<br>"
' get value of Querystring
Response.Write "Querystring <br>"
Response.Write Request.Querystring("sPWD") & "<br>"

Response.write "<br>"
'Test the values against each other
if rsResults("Comp_PWD") = Request.Querystring("sPWD") then
Response.write "Test Suceeded"
else
Response.write "try Again<br>"
end if

Response.write "<br>"
' Test If Statement

if i = 2 then
Response.Write "Test if Worked"
Else
Response.Write "Test if Broken"
End If


rsResults.Close
conn.Close
%>

*************

Here's the results

*************

RecordSet
demo
Querystring
demo

try Again

Test if Worked

*************

As you can see from the above the Recordset and the Querystring matches. I tried diffrent flavours, setting the Quearystring equal to anothe value but still no joy .. what am I doing wrong?

HELP!!

Feb 8th, 2001, 02:35 AM
Hi .... try this again ...

Dim conn 'Connection
Dim rsResults 'Record Set
Dim aConnect 'Connection String
dim i 'Testing
i = False

aConnect = "Provider=SQLOLEDB.1;Persist Security Info=False;Data Source=DEV-SVR;Initial Catalog=Alchemy;User ID=Guest;Password=;ConnectionTimeout=10;"

Set conn = Server.CreateObject("ADODB.Connection")
Set rsResults = Server.CreateObject ("ADODB.Recordset")
conn.Mode = abModeReadWrite
conn.ConnectionString = aConnect
conn.open

Set rsResults = conn.Execute("SELECT * FROM Company WHERE Comp_UID = '" & Request.Querystring("sUID") & "'")

Do While Not rsResults.EOF
if rsResults("Comp_PWD") = Request.Querystring ("sPWD") then
i = True
end if
rsResult.Movenext
Loop

if i = True then
Response.write "Record Found !"
else
response.write "No record found !"
end if

rsResults.Close
conn.Close