[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??
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?
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?
Re: Oops: what's wrong with this???
Quote:
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....
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 [].
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|| ....
Re: what's wrong with this???
I'm questioning the use of ().
Re: what's wrong with this???
Quote:
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").
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.
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?
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?
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!!