Return value

S

solomon_13000

The code bellow functions well. However if I want to obtain a return
value using the code bellow, how is it done?

<%
Sub RunQueryString (pSQL,parms)
on error resume next
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.MapPath("/db/upload/stelladb.mdb") & ";"
Set cmd = Server.CreateObject("adodb.command")
With cmd
..CommandText = pSQL
..CommandType = 1
set .ActiveConnection = conn
err.clear
..Execute ,parms,128
if Err.number <> 0 then
Response.Write(Err.number & ":" & Err.Description & "
")
end if
on Error goto 0
End with
conn.close
Set conn = nothing
End Sub
%>


<%
if Request.QueryString("Action") = 1 then
username = Trim(request.form("username"))
password = Trim(request.form("password"))
if username <> "" and password <> "" then
arParms = Array(username,password)
sql = "SELECT Count(*) FROM Account WHERE username=? AND password=?"
RunQueryString sql, arParms
end if
end if
%>
 
S

solomon_13000

I am trying to obtain a return value for the sql statement bellow:

sql = "SELECT Count(*) FROM Account WHERE username=? AND password=?"

which can be found on the code which I have posted.
 
S

solomon_13000

I did this:

<%
Sub RunQueryString (pSQL,parms)
Set rs = Server.CreateObject("ADODB.Recordset")
..Execute rs,parms,128
End Sub
%>

<%
sql = "SELECT username,password FROM Account WHERE username=? AND
password=?"
RunQueryString sql, arParms
response.write rs("username")
%>

the results was HTTP:500 Internal server error.
 
S

solomon_13000

I have even tried the following method:

Sub RunQueryString (pSQL,parms)
Set rs = Server.CreateObject("ADODB.Recordset")
Dim p
set rs = .Execute(p,parms,128)
End Sub

and I am getting the following error:

Type: Nothing

Microsoft VBScript runtime error '800a01a8'

Object required
 
M

Mike Brind

solomon_13000 said:
The code bellow functions well. However if I want to obtain a return
value using the code bellow, how is it done?

<%
Sub RunQueryString (pSQL,parms)
on error resume next
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.MapPath("/db/upload/stelladb.mdb") & ";"
Set cmd = Server.CreateObject("adodb.command")
With cmd
.CommandText = pSQL
.CommandType = 1
set .ActiveConnection = conn
err.clear
.Execute ,parms,128
if Err.number <> 0 then
Response.Write(Err.number & ":" & Err.Description & "
")
end if
on Error goto 0
End with
conn.close
Set conn = nothing
End Sub
%>


<%
if Request.QueryString("Action") = 1 then
username = Trim(request.form("username"))
password = Trim(request.form("password"))
if username <> "" and password <> "" then
arParms = Array(username,password)
sql = "SELECT Count(*) FROM Account WHERE username=? AND password=?"
RunQueryString sql, arParms
end if
end if
%>

You can't obtain a return value from a subroutine, so from the
additional code you have posted, I assume you want to check the value
of "sql". If that's the case, just Response.Write sql before
RunQueryString sql, arParms.
 
S

solomon_13000

Actually I intend to obtain a return value using the statement bellow:

sql = "SELECT Count(*) FROM Account WHERE username=? AND password=?"
 
S

solomon_13000

This is the complete code In which I intend to obtain a return value. I
am getting the following error:


Microsoft VBScript runtime error '800a01a8'

Object required

and the error is pointing to response.write rs(0)


<%
Sub RunQueryString (pSQL,parms)
on error resume next
Set conn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.MapPath("/db/upload/stelladb.mdb") & ";"
Set cmd = Server.CreateObject("adodb.command")
With cmd
.CommandText = pSQL
.CommandType = 1
set .ActiveConnection = conn
err.clear
Dim banana
Set rs = .Execute(banana,parms,128)
if Err.number <> 0 then
Response.Write(Err.number & ":" & Err.Description &
"<br>")
end if
on Error goto 0
End with
conn.close
Set conn = nothing
End Sub
%>

<%
if Request.QueryString("Action") = 1 then
username = Trim(request.form("username"))
password = Trim(request.form("password"))
if username <> "" and password <> "" then
arParms = Array(username,password)
sql = "SELECT Count(*) FROM Account WHERE username=? AND
password=?"
RunQueryString sql, arParms
response.write rs(0)
end if
end if
%>
 
M

Martin Walke

Hi Solomon,

The problem (in all your posts) is that you're not referencing the
connection object when you use the execute statement. You must precede the
statement with your connection i.e.

Set rs = conn.Execute(banana,parms,128)

or surround it with a 'with' construct

with conn
Set rs = .Execute(banana,parms,128)
end with

I would also recommend you use the constant values for the "options"
parameter (adCmd...) as who knows what 128 means

HTH
Martin
 
M

Martin Walke

Ah - just spotted that you are using the 'with' construct!

The error is complaining that rs doesn't exist or not initialised. As far as
i can see, option 128 (which is 80H) is adExecuteNoRecords.

The clue may be in that!

Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top