Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

SQL problem in ASP page

Hi all,

I am working on a WAP project and am experiencing problems passing a variable to an SQL statement. The reason why I say this is that the variable appears to be storing the information as I can print this variable onto the screen, the staement is OK when I pass the information directly to the statement but this is not flexible for me. Below is the code:

<%@ Language = "JScript"; %>
<% Response.ContentType = "text/vnd.wap.wml" %>
<?xml version="1.0"?>
<!-- #include file="adojavas.inc" -->
<!DOCTYPE wml PUBLIC "-//OPENWAVE.COM//DTD WML 1.3//EN" "http://www.openwave.com/dtd/wml13.dtd">

<!-- London Attractions ASP file -->

<wml>

     <head>
          <meta forua="true" http-equiv="Pragma" content="no-cache"/>
          <meta forua="true" http-equiv="Cache-Control" content="no-cache, must-revalidate"/>
     </head>

           <%
               conn = Server.CreateObject("ADODB.Connection");
               rs = Server.CreateObject("ADODB.Recordset");
               lbrRs = Server.CreateObject("ADODB.Recordset");


               conn.Open("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" +
                              Server.MapPath("city.mdb") + ";");

               //SQL Query
               initQuery = "SELECT LocationID, Name FROM Area";
                         
               rs.Open(initQuery, conn, adOpenForwardOnly, adLockReadOnly, adCmdText);
               
          %>

     <card id="area" title = "London Areas">
      <p>
        <b>The Attractions Page</b>
      </p>
      <p>
          <b>Please select the area you are visiting:</b><br/>

          <select name="area" title="Select Area">

          <%
               
               while (!rs.EOF)
               {
         
                    Response.Write("<option value=\" ");
                    Response.Write(rs("LocationID"));
                    //Response.Write(title=\" + rs("LocationID") + "\");
                    Response.Write("\">");
                    Response.Write(rs("Name"));
                    Response.Write("</option>");
                    rs.MoveNext();
               }
               
          %>

          </select>    
      </p>

       <do type="accept" label="OK">
          <go href="#venues" method="get">
               <postfield name="area" value="$(area)"/>
          </go>
       </do>

     </card>

     <card id="venues" title="Area Venues">
          <p>
               <b>List of venues:</b>
          </p>
          <p>

          <%

//Below is where Im experiencing problems. Please help thanks.

          place = Request.QueryString( "area");
          lbrQuery = "SELECT * FROM Attraction WHERE LocationID=' &place& ' ";
          lbrRs.Open(lbrQuery, conn, adOpenForwardOnly, adLockReadOnly, adCmdText);


               Response.Write( place);

               while( !lbrRs.EOF) {
                    Response.Write( lbrRs( "Name") + "<br/>");
                    lbrRs.MoveNext();
               }

               conn.Close();
          %>
          </p>

     </card>

</wml>
0
jimbo1278
Asked:
jimbo1278
  • 3
  • 3
  • 2
  • +2
1 Solution
 
Arthur_WoodCommented:
without knowning ANYTHING about yout table, I would suspect that LocationID is a NUMBER field, not a string, in which case, these lines:

 lbrQuery = "SELECT * FROM Attraction WHERE LocationID=' &place& ' ";
         lbrRs.Open(lbrQuery, conn, adOpenForwardOnly, adLockReadOnly, adCmdText);

will not work, as Access will try to find a LOCATIONID as a

 lbrQuery = "SELECT * FROM Attraction WHERE LocationID = " & place
         lbrRs.Open(lbrQuery, conn, adOpenForwardOnly, adLockReadOnly, adCmdText);

0
 
Arthur_WoodCommented:
or possibly,

lbrQuery = "SELECT * FROM Attraction WHERE LocationID = " + place;
lbrRs.Open(lbrQuery, conn, adOpenForwardOnly, adLockReadOnly, adCmdText);

0
 
jimbo1278Author Commented:
The LocationID is set as a text field, in the database its a 3 letter field to identify the area the attractions are in. ie LBR is London Bridge. Will the query work as it is ?
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
adatheladCommented:
Hi,
Try this:

lbrQuery = "SELECT * FROM Attraction WHERE LocationID='"  & place & "'"

lbrRs.Open(lbrQuery, conn, adOpenForwardOnly, adLockReadOnly, adCmdText)

Cheers
0
 
Arthur_WoodCommented:
what do you mean by:

"the staement is OK when I pass the information directly to the statement but this is not flexible for me"

what is not FLEXIBLE?

what do you need?

AW

0
 
jimbo1278Author Commented:
If I said

lbrQuery = "SELECT * FROM Attraction WHERE LocationID='LBR'"

then this works but I have other 3 letter codes that I am passing the hope was that place would accept any 3 letter area code.




0
 
adatheladCommented:
jimbo,

does this not work?
lbrQuery = "SELECT * FROM Attraction WHERE LocationID='"  & place & "'"

Cheers
0
 
jimbo1278Author Commented:
I tired what you said but still the same problem its as if the quey doesnt read the variable
0
 
spongieCommented:
Change this:

lbrQuery = "SELECT * FROM Attraction WHERE LocationID=' &place& '"

to this:

lbrQuery = "SELECT * FROM Attraction WHERE LocationID='" & place & "'"

I think you have included the variable [place] within the quotes thus making it a literal
0
 
walterecookCommented:
This question has been classified as abandoned.  I will make a recommendation to the moderators on its resolution in approximately 4 days.  I would appreciate any comments by the experts that would help me in making a recommendation.

It is assumed that any participant not responding to this request is no longer interested in its final deposition.

If the asker does not know how to close the question, the options are here:
http://www.experts-exchange.com/help.jsp#hs5

walterecook
EE Cleanup Volunteer
0
 
walterecookCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: spongie {http:#8328240}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

walterecook
EE Cleanup Volunteer
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now