|
-
Aug 30th, 2005, 11:04 AM
#1
Thread Starter
Addicted Member
[RESOLVED] <Resolved> what's wrong with this???
Hey u all...
I have recently started using JS on ASP, but somewhere something went wrong: I could'nt compare two strings!!
Code:
<%@ LANGUAGE = JScript %>
<html>
<%var tester = (Request.QueryString("t")), oConn, oRs, filePath, r,i=1,b=false;
filePath = Server.MapPath("pics.mdb");
oConn = Server.CreateObject("ADODB.Connection");
r = Server.CreateObject("adodb.recordset");
oConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath);
oRs = oConn.Execute("SELECT * From TableList");
while (!oRs.eof) {
b=b||(tester==oRs("name"));
Response.Write(oRs("name") + ": " + b + "<BR> " );
if (b) break;
oRs.MoveNext();}
oRs.close();
if (b){
Response.Write("<B>" +tester +" is valid!!</b>");
}else{
Response.Write(tester+ " is invalid!!");}%>
My server's response is always invalid, even if ?t='s value is in the table.
What should I do??
Last edited by Lemon Lime; Sep 5th, 2005 at 11:49 AM.
Reason: resolved
I've had enough with sainity!
What's the use of it anyway?
-
Sep 1st, 2005, 05:08 AM
#2
PowerPoster
Re: what's wrong with this???
Having no knowledge of ASP what so ever...
b=b||(tester==oRs("name"));
Whats that? Shouldn't there be an if statement there?
-
Sep 1st, 2005, 08:14 AM
#3
Thread Starter
Addicted Member
Re: what's wrong with this???
I write codes like this for ages! it means that every loop b flag will turn on if oRs("name") and tester are the same and stays on.
The problem is that no matter what, b will stay false, even if they are the same (by value).
Writting like this is the same as
Code:
if (oRs("name") == tester) b=true; else b=false;
But if the next time oRs("name") is not identical to tester b will be false so b is false in the beginning, after checking up equivalency just use OR operator like this:
Code:
if (oRs("name") == tester) b=true; else b=false ||b;
Well, (oRs("name") == tester) is a logical statement, so what's the differance?
Know what? even
Code:
b||=(tester==oRs("name"));
should have work the same.
Am I missing something?
I've had enough with sainity!
What's the use of it anyway?
-
Sep 1st, 2005, 08:24 AM
#4
Thread Starter
Addicted Member
Re: Oops: what's wrong with this???
Know what? even
b||=(tester==oRs("name"));
should have work the same.
Ooops, it does'nt work.... but
Code:
b=b||(tester==oRs("name"));
does.
Huge Oops....
I've had enough with sainity!
What's the use of it anyway?
-
Sep 2nd, 2005, 04:14 AM
#5
Re: what's wrong with this???
There's no ||= operator.
Anyway, are you sure oRs("name") yields something meaningful? If it's an array, the array index operator in JScript is [].
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 3rd, 2005, 01:35 PM
#6
Thread Starter
Addicted Member
Re: what's wrong with this???
Hey CornedBee!
The oRs("name") is a record on my table. as you can see on the source
Code:
oConn = Server.CreateObject("ADODB.Connection");
r = Server.CreateObject("adodb.recordset");
oConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath);
oRs = oConn.Execute("SELECT * From TableList")
That's not the problem! The problem starts when I'm trying to compare texts in the line b=b|| ....
I've had enough with sainity!
What's the use of it anyway?
-
Sep 3rd, 2005, 01:41 PM
#7
Re: what's wrong with this???
I'm questioning the use of ().
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 3rd, 2005, 02:48 PM
#8
Thread Starter
Addicted Member
Re: what's wrong with this???
 Originally Posted by CornedBee
I'm questioning the use of ().
When I tried using [] like so: oRs["name"] i got undefined.
The usage for data from ADODB inside records is oRs("name").
I've had enough with sainity!
What's the use of it anyway?
-
Sep 3rd, 2005, 05:27 PM
#9
Re: what's wrong with this???
Nevertheless, try this for a moment:
Code:
while (!oRs.eof) {
var name = oRs("name");
// Output name and typeof(name) here.
b=b||(tester==name);
I wonder what those are.
Oh, and might I mention how wrong it is to write the existence test in the script in the first place? Put the query in the SQL.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 5th, 2005, 10:07 AM
#10
Thread Starter
Addicted Member
Re: what's wrong with this???
CornedBee dude!!
both of them are Objects
I've changed a bit the code and still nothing:
Code:
<%@language =javascript%>
<html>
<%var tester = " ", tester2 = " ", oConn, oRs, filePath, r,i=1,b=false;
tester = (Request.QueryString("t"));
filePath = Server.MapPath("pics.mdb");
oConn = Server.CreateObject("ADODB.Connection");
r = Server.CreateObject("adodb.recordset");
oConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath);
oRs = oConn.Execute("SELECT * From TableList");
while (!oRs.eof) {
tester2 = oRs("name");
Response.Write("tst:"+(tester==tester2)+" ");
Response.Write(typeof(oRs("name")) + "** " );
Response.Write(typeof(tester) + "@@ ");
Response.Write(typeof(tester2) + "## ");
b=b||(tester==tester2);
Response.Write(tester2 + ": " + b + "<BR> ");
if (b) break;
oRs.MoveNext();}
oRs.close();
if (b){
Response.Write("<B>" +tester +" is valid!!</b>");
}else{
Response.Write(tester+ " is invalid!!");}%>
my screen looks like this:
address:123.asp?t=yeshiva
Code:
tst:false object** object@@ object## yeshiva: false
tst:false object** object@@ object## volunteering: false
yeshiva is invalid!!
Any ideas?
I've had enough with sainity!
What's the use of it anyway?
-
Sep 5th, 2005, 10:43 AM
#11
Re: what's wrong with this???
Wait a moment, everything is an object there? Ugh!
OK, after browsing the docs, I'm not one bit smarter. All code examples are in VBScript, which makes it somewhat tiresome.
Have you tried calling toString() on the objects?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 5th, 2005, 11:49 AM
#12
Thread Starter
Addicted Member
Resolved: what's wrong with this???
Code:
<%@language =javascript%>
<html>
<%var tester = " ",oConn, oRs, filePath, r,i=1,b=false;
tester = new String((Request.QueryString("t")));
filePath = Server.MapPath("pics.mdb");
oConn = Server.CreateObject("ADODB.Connection");
r = Server.CreateObject("adodb.recordset");
oConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath);
oRs = oConn.Execute("SELECT * From TableList");
while (!oRs.eof) {
b=b||(tester.toLowerCase( )==oRs("name").value.toLowerCase( ));
if (b) break;
oRs.MoveNext();}
oRs.close();
if (b){
Response.Write("<B>" +tester +" is valid!!</b>");
}else{
Response.Write(tester+ " is invalid!!");}%>
THAT'S IT
.value is the answer
debugged it twice!!
I've had enough with sainity!
What's the use of it anyway?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|