Return value

Discussion in 'ASP General' started by solomon_13000, Jun 15, 2006.

  1. 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
    %>
     
    solomon_13000, Jun 15, 2006
    #1
    1. Advertising

  2. 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.


    solomon_13000 wrote:
    > 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
    > %>
     
    solomon_13000, Jun 15, 2006
    #2
    1. Advertising

  3. 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.

    solomon_13000 wrote:
    > 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
    > %>
     
    solomon_13000, Jun 15, 2006
    #3
  4. 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


    solomon_13000 wrote:
    > 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
    > %>
     
    solomon_13000, Jun 15, 2006
    #4
  5. solomon_13000

    Mike Brind Guest

    solomon_13000 wrote:
    > 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.

    --
    Mike Brind
     
    Mike Brind, Jun 15, 2006
    #5
  6. Actually I intend to obtain a return value using the statement bellow:

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


    solomon_13000 wrote:
    > 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
    > %>
     
    solomon_13000, Jun 15, 2006
    #6
  7. 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
    %>




    solomon_13000 wrote:
    > 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
    > %>
     
    solomon_13000, Jun 15, 2006
    #7
  8. solomon_13000

    Martin Walke Guest

    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

    "solomon_13000" <> wrote in message
    news:...
    > 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
    > %>
    >
    >
    >
    >
    > solomon_13000 wrote:
    >> 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
    >> %>

    >
     
    Martin Walke, Jun 16, 2006
    #8
  9. solomon_13000

    Martin Walke Guest

    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

    "solomon_13000" <> wrote in message
    news:...
    > 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
    > %>
    >
    >
    >
    >
    > solomon_13000 wrote:
    >> 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
    >> %>

    >
     
    Martin Walke, Jun 16, 2006
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PvdK
    Replies:
    0
    Views:
    2,981
  2. Seong-Kook Shin
    Replies:
    1
    Views:
    497
    Richard Bos
    Jun 18, 2004
  3. Greenhorn
    Replies:
    15
    Views:
    834
    Keith Thompson
    Mar 6, 2005
  4. CSINVA
    Replies:
    6
    Views:
    409
    Paul Delcogliano
    Nov 7, 2007
  5. Tim Fröglich

    Getting ID, calling url, search for value, return value

    Tim Fröglich, Jan 7, 2006, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    144
    Josh Twist
    Jan 10, 2006
Loading...

Share This Page