Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 14th, 2006, 01:53 PM
Authorized User
 
Join Date: Jun 2006
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
Default Passing Variable to Query

I'm a newbie to ASP and I'm trying to pass a variable from a form to a query. Here's my form page code:

Code:
<html><body>
<form action="findnow.asp" method="get">
<P>
String:  <INPUT type=text id=l_name  name=l_name> <br>

</P>
<input type="submit" value="Search" id="submit1" name="submit1">
</form>
</body></html>


And here's my ASP code:

<%
    Option Explicit
    Dim l_name
    Dim rsCustSurvey
    Dim raction_summary
    Dim Conn
    l_name = Request.QueryString("l_name")
    response.write(l_name)

    set Conn=Server.CreateObject("ADODB.Connection") 'create Server Database Connection Object
    set rsCustSurvey = server.CreateObject("ADODB.Recordset") 'create RecordSet Conn Obj
    set raction_summary =server.CreateObject("ADODB.Recordset") 'number of surveys received


    Conn.open "Driver={SQL Server}; Server=server01;Database=System;UID=u;PWD=p;"

    set rsCustSurvey = conn.Execute ("Select ProblemDescriptionTrunc, Action_Summary, ProblemItem, Problem_Solution002, " _
        & " Problem_Description002, RootCause, LastModifiedBy, dbo.TTS_Main.AssignedGroup, dbo.TTS_Main.Last_Name, dbo.TTS_Main.First_Name, " _
dbo.TTS_Main.AssignedGroup, AssignedTechnician, ModificationHistory "_
        & " From tts_main " _
    & " Where Last_Name LIKE '%l_name%' ")



    if rsCustSurvey.EOF then 'traps for IF recordset is empty THEN:
        Response.Write "There is no data"
        Response.End
    end if


%>

    <%do while not rsCustSurvey.EOF%></do>
    <%response.write rsCustSurvey("Last_Name")%>
    <%rsCustSurvey.MoveNext%>
    <%loop%>


<%
    set rsCustSurvey = nothing
    set conn = nothing
%>

When I hardcode the search string in the query, it returns data as it should, but with the code above, I'm getting no data.

Suggestions?

Thanks!
Dale

 
Old November 14th, 2006, 02:09 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try
Code:
" Where Last_Name LIKE '%" & l_name & "%' "
HTH,

Chris

 
Old November 14th, 2006, 03:27 PM
Authorized User
 
Join Date: Jun 2006
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks! That worked. I thought I had tried all various incantations of the quotes and ampersands, but evidently not.

Dale






Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Variable Query rsm42 ASP.NET 1.0 and 1.1 Basics 1 February 10th, 2007 01:05 PM
Passing a Variable LarryS Beginning PHP 1 August 8th, 2006 07:52 AM
passing variable tbekarov ASP.NET 2.0 Professional 7 February 1st, 2006 04:16 PM
Passing variable to a public variable Hudson40 Access VBA 2 February 25th, 2005 06:23 AM
Passing a variable trekmp ADO.NET 1 March 4th, 2004 01:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.