|
 |
asp_databases thread: RE: Can anybody help!
Message #1 by "Kim Iwan Hansen" <kimiwan@k...> on Sat, 20 Jul 2002 15:05:38 +0200
|
|
If you try and go through your code with an example, then you'll realise it
pretty soon.
First you open the recordset and until objRS.eof you write out all the
usernames that are "username". When it exits the loop, it's because the
objRS is .eof - and this is where you check if objRS is eof again (which
it'll always be - because it's either .eof from the beginning, or you've
looped through the recordset till it's .eof).
I guess you don't really want to loop through the recordset and write the
username out more than once if it exists, so try this instead:
if not objRS.eof then
response.write "<H2> Your User Name is " & strUserName & "</H2>"
else
response.write "The database does not contain any <H1>" & strUserName &
"</H1>"
end if
Remember, you're already retrieving only the records where username in the
database is the same as the username that was entered in the form - so you
don't have to check that again.
-Kim
> -----Original Message-----
> From: Abdullah Jahir Uddin [mailto:shahinbd@h...]
> Sent: 20. juli 2002 08:57
> To: ASP Databases
> Subject: [asp_databases] Can anybody help!
>
>
> I want retrieve one field(UserName)from the DB(DB has only one field-
> UserName). But it is not retrieving the field(UserName) although it is in
> the DB. When I write the currect UserName, in any case it is
> giving "DataBase does not contain any...I think the problem is in the EOF
> condition, but I don't know where is the problem. I'm spending too much
> time on it. Can anybody help?
>
> Thanks
> Abdullah
>
> Here is the code:
>
> <% Option Explicit %>
> <!--#include file="DataStore12.asp"-->
>
> <%
> Dim strUserName
>
> strUserName=Request.Form("UserName")
>
> Dim objRS , strSQL
> Set objRS= Server.CreateObject("ADODB.Recordset")
> strSQL="select * from table1 where UserName=' " & strUserName & " ' ;"
> objRS.Open strSQL,objConn
>
> while not objRS.EOF
> if objRS("UserName")=Request.Form("UserName") then
> Response.Write "<H2> Your User Name is " & strUserName & "</H2>"
> else
> objRS.movenext
> end if
> wend
>
> if objRS.EOF then
> Response.Write "The database does not contain any " & _
> "<H1>" & strUserName & "</H1>"
> End if
>
> objRS.Close
> Set objRS= Nothing
> %>
Message #2 by arshad siddiqui <ash_arshad@y...> on Sat, 20 Jul 2002 03:57:46 -0700 (PDT)
|
|
Hi Abdullah,
I dont know which type of connection are you using.I
think its in include file.First of all use the
connection in your ASP without any include file.where
is "objconn".
put
Set objconn=Server.CreateObject("ADODB.Connection")
objconn.open "DSN=whatever;UID=sa;PWD=whatever;"
(or use DSN less connection)
second thing remove semicolon from your sql
statement.If its not working then use
do while not objrs.eof
and instead of wend use loop
I think this should work.
regards
--Arshad--
--- Abdullah Jahir Uddin <shahinbd@h...> wrote:
> I want retrieve one field(UserName)from the DB(DB
> has only one field-
> UserName). But it is not retrieving the
> field(UserName) although it is in
> the DB. When I write the currect UserName, in any
> case it is
> giving "DataBase does not contain any...I think the
> problem is in the EOF
> condition, but I don't know where is the problem.
> I'm spending too much
> time on it. Can anybody help?
>
> Thanks
> Abdullah
>
> Here is the code:
>
> <% Option Explicit %>
> <!--#include file="DataStore12.asp"-->
>
> <%
> Dim strUserName
>
> strUserName=Request.Form("UserName")
>
> Dim objRS , strSQL
> Set objRS= Server.CreateObject("ADODB.Recordset")
> strSQL="select * from table1 where UserName=' " &
> strUserName & " ' ;"
> objRS.Open strSQL,objConn
>
> while not objRS.EOF
> if objRS("UserName")=Request.Form("UserName") then
> Response.Write "<H2> Your User Name is " &
> strUserName & "</H2>"
> else
> objRS.movenext
> end if
> wend
>
> if objRS.EOF then
> Response.Write "The database does not contain any "
> & _
> "<H1>" & strUserName & "</H1>"
> End if
>
> objRS.Close
> Set objRS= Nothing
> %>
__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com
Message #3 by "Abdullah Jahir Uddin" <shahinbd@h...> on Sat, 20 Jul 2002 08:56:58
|
|
I want retrieve one field(UserName)from the DB(DB has only one field-
UserName). But it is not retrieving the field(UserName) although it is in
the DB. When I write the currect UserName, in any case it is
giving "DataBase does not contain any...I think the problem is in the EOF
condition, but I don't know where is the problem. I'm spending too much
time on it. Can anybody help?
Thanks
Abdullah
Here is the code:
<% Option Explicit %>
<!--#include file="DataStore12.asp"-->
<%
Dim strUserName
strUserName=Request.Form("UserName")
Dim objRS , strSQL
Set objRS= Server.CreateObject("ADODB.Recordset")
strSQL="select * from table1 where UserName=' " & strUserName & " ' ;"
objRS.Open strSQL,objConn
while not objRS.EOF
if objRS("UserName")=Request.Form("UserName") then
Response.Write "<H2> Your User Name is " & strUserName & "</H2>"
else
objRS.movenext
end if
wend
if objRS.EOF then
Response.Write "The database does not contain any " & _
"<H1>" & strUserName & "</H1>"
End if
objRS.Close
Set objRS= Nothing
%>
Message #4 by "Abdullah Jahir Uddin" <shahinbd@h...> on Sun, 28 Jul 2002 02:25:52
|
|
> I want retrieve one field(UserName)from the DB(DB has only one field-
U> serName). But it is not retrieving the field(UserName) although it is
in
t> he DB. When I write the currect UserName, in any case it is
g> iving "DataBase does not contain any...I think the problem is in the
EOF
c> ondition, but I don't know where is the problem. I'm spending too much
t> ime on it. Can anybody help?
> Thanks
A> bdullah
> Here is the code:
> <% Option Explicit %>
<> !--#include file="DataStore12.asp"-->
> <%
D> im strUserName
> strUserName=Request.Form("UserName")
> Dim objRS , strSQL
S> et objRS= Server.CreateObject("ADODB.Recordset")
s> trSQL="select * from table1 where UserName=' " & strUserName & " ' ;"
o> bjRS.Open strSQL,objConn
> while not objRS.EOF
i> f objRS("UserName")=Request.Form("UserName") then
R> esponse.Write "<H2> Your User Name is " & strUserName & "</H2>"
e> lse
o> bjRS.movenext
e> nd if
w> end
> if objRS.EOF then
R> esponse.Write "The database does not contain any " & _
"> <H1>" & strUserName & "</H1>"
E> nd if
> objRS.Close
S> et objRS= Nothing
%
Message #5 by "Abdullah Jahir Uddin" <shahinbd@h...> on Sun, 28 Jul 2002 02:28:31
|
|
Hello Arshad & Kim,
Many thanks for your reply.Sorry for the delay.
cheers
Abdullah
Message #6 by Vijay G <happygv@y...> on Sun, 28 Jul 2002 19:48:49 -0700 (PDT)
|
|
Try to print the value if strSql using Response.Write, copy the same and run it on the DB to find if the result is perfect. Else
problem is with the query or with the form value(UserName).
Also there is no need for the IF statement within the While ....EOF() loop, since you filter the data relevant to the Form's
UserName value. You can better remove that.
Hope this helps. Let me know.
Regards,
Vijay.G
Abdullah Jahir Uddin wrote:> I want retrieve one field(UserName)from the DB(DB has only one field-
U> serName). But it is not retrieving the field(UserName) although it is
in
t> he DB. When I write the currect UserName, in any case it is
g> iving "DataBase does not contain any...I think the problem is in the
EOF
c> ondition, but I don't know where is the problem. I'm spending too much
t> ime on it. Can anybody help?
> Thanks
A> bdullah
> Here is the code:
>
<> !--#include file="DataStore12.asp"-->
>
---------------------------------
Do You Yahoo!?
Yahoo! Health - Feel better, live better
Message #7 by "Drew, Ron" <RDrew@B...> on Mon, 29 Jul 2002 08:54:24 -0400
|
|
Your sql statement has embedded spaces..next time do a response write to
see it to help debugging. I also changed your eof checks. This works,
just change the name in the database and take out the connect.
<% Option Explicit %>
<% Dim strUserName, Conn, mdbPath, gothit
'strUserName=3D"ADrew"
strUserName=3D"Drew"
gothit =3D "n"
Set Conn =3D Server.CreateObject("ADODB.Connection")
mdbPath =3D Server.MapPath("test.mdb")
Conn.Open "Provider=3DMicrosoft.Jet.OLEDB.4.0;" & _
"Data Source=3D" & mdbPath & ";" & _
"User Id=3Dadmin;" & _
"Password=3D;"
Dim objRS , strSQL
Set objRS=3D Server.CreateObject("ADODB.Recordset")
strSQL=3D"select * from testname where Name=3D'" & strUserName & "' ;"
Response.Write strSQL
objRS.Open strSQL,Conn
while not objRS.EOF
if objRS("Name")=3D strUserName then
gothit =3D "y"
Response.Write "<H2> Your User Name is " & objRS("Name") & "</H2>"
end if
objRS.movenext
wend
if objRS.EOF then
if gothit =3D "n" then
Response.Write "The database does not contain any " & _
"<H1>" & strUserName & "</H1>"
end if
end if
objRS.Close
Set objRS=3D Nothing
Conn.Close
Set Conn=3D Nothing
%>
-----Original Message-----
From: Abdullah Jahir Uddin [mailto:shahinbd@h...]
Sent: Saturday, July 27, 2002 10:26 PM
To: ASP Databases
Subject: [asp_databases] Re: Can anybody help!
> I want retrieve one field(UserName)from the DB(DB has only one field-
U> serName). But it is not retrieving the field(UserName) although it is
in
t> he DB. When I write the currect UserName, in any case it is
g> iving "DataBase does not contain any...I think the problem is in the
EOF
c> ondition, but I don't know where is the problem. I'm spending too
c> much
t> ime on it. Can anybody help?
> Thanks
A> bdullah
> Here is the code:
> <% Option Explicit %>
<> !--#include file=3D"DataStore12.asp"-->
> <%
D> im strUserName
> strUserName=3DRequest.Form("UserName")
> Dim objRS , strSQL
S> et objRS=3D Server.CreateObject("ADODB.Recordset")
s> trSQL=3D"select * from table1 where UserName=3D' " & strUserName & "
' ;"
o> bjRS.Open strSQL,objConn
> while not objRS.EOF
i> f objRS("UserName")=3DRequest.Form("UserName") then
R> esponse.Write "<H2> Your User Name is " & strUserName & "</H2>"
e> lse
o> bjRS.movenext
e> nd if
w> end
> if objRS.EOF then
R> esponse.Write "The database does not contain any " & _
"> <H1>" & strUserName & "</H1>"
E> nd if
> objRS.Close
S> et objRS=3D Nothing
%
|
|
 |