Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    recordset problem in session

    I have database in sql server 2000. I am creating session starting from login page. session value is successfully passed to 2nd page. I want to extract profile information from the same table (employees) that contains login and password.
    in 2nd page, recordset in vbscript is giving error.
    my record set code is given below.

    <!--#include file="Connections/test_travel.asp" -->
    <%
    Dim profile_show
    Dim profile_show_numRows
    a = session("sessSignum")
    Set profile_show = Server.CreateObject("ADODB.Recordset")
    profile_show.ActiveConnection = MM_test_travel_STRING
    profile_show.Source = "SELECT * FROM dbo.test_emp WHERE Signum = ' " & session("sessSignum") & " '"
    profile_show.CursorType = 0
    profile_show.CursorLocation = 2
    profile_show.LockType = 1
    profile_show.Open()

    profile_show_numRows = 0
    %>

    <body>
    <form id="form1" name="form1" method="post" action="">

    <% b =(profile_show.Fields.Item("Signum").Value)%></form>

    </body>
    </html>
    <%
    profile_show.Close()
    Set profile_show = Nothing
    %>

    the code runs fine if we give exact value in sql WHERE clause. but putting in some variable give error.
    urgent help needed.

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    1. If your code gives you an error message, post the error message.
    2. If your error happens when you fire SQL statements at a database, response.write() your SQL statement, and post it.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You have a leading and trailing space in the Signum value.
    Code:
    profile_show.Source = "SELECT * FROM dbo.test_emp WHERE Signum = ' " & session("sessSignum") & " '"
    Change it to:
    Code:
    profile_show.Source = "SELECT * FROM dbo.test_emp WHERE Signum = '" & session("sessSignum") & "'"
    If you assign the session to variable a then you can replace the session in the query to a.

    And also you need to always check if the recordset contains records or not before displaying them. This is to avoid unexpected runtime errors if no record is found.
    Code:
    <%
    if not profile_show.EOF and not profile_show.BOF then
      'recordset contains record, do what you want
      response.write "Signum:" & profile_show.Fields.Item("Signum").Value
    else
      'recordset is empty, display error
      response.write "Record not found."
      profile_show.close
      set profile_show = nothing
      response.end
    end if
    %>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •