1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Dynamic SQL Statement

Discussion in 'C#' started by cogsworth12000, Dec 10, 2007.

  1. #1
    Hello,

    I have an ASP application that pulls product data from an access database. The data is displayed in several columns [Product Name] [Product Number] [Cateogry]... Under the column header I have a select box that I populate with values from the database as well. When a user selects an item from the select box I would like the query to run again and filter on what was selected in the select box. Currently I have an onchange event for the select box which reloads the page, I also have a global Session variable for the SQL statement. I don't have a way to set the session variable in the javascript onchange event though. Any assistance or redesign would be appreciated.

    URL: http://www.ehacstl.com/product_display.asp
    Code:
    .
    .
    function onCategory(catid)
    {
    alert("in OnCategory")
    NewdynSQLProduct="Select * from products a, product_category b where b.product_category_id = "
    NewdynSQLProduct= NewdynSQLProduct + catid
    NewdynSQLProduct=NewdynSQLProduct + "' and b.product_category = a.category"

    window.location.reload()
    }
    .
    .
    .
    <select size="1" name="ProductCategory" onchange="return onCategory(document.Form1.ProductCategory.options[document.Form1.ProductCategory.selectedIndex].value);">
    <%
    strSQL="select product_category_id, product_category from product_category where category_active='YES'"
    set RS = Conn.Execute(strSQL)
    Do until RS.EOF
    %>
    <option value="<%response.write RS.fields("product_category_id")%>"><%response.write RS.fields("product_category")%></option>
    <%
    RS.MoveNext
    loop
    RS.Close
    %>
    </select>
    .
    .
    .
    <%
    strSQL=Session("dynSQLProduct")
    response.write ("SQL: " & strSQL)
    set RS = Conn.Execute (strSQL)
    Do until RS.EOF
    response.write ("<tr>")
    response.write ("<td> <input type=""checkbox"" name=""chkBox"" value="" ") & RS.fields("product_id") & (" "" </td>")
    response.write ("<td>") & RS.fields("product_name") & ("</td>")
    response.write ("<td>") & RS.fields("product_number")&("</td>")
    response.write ("<td>") & RS.fields("category") & ("</td>")
    productprice=RS.fields("product_price")
    productprice=formatnumber(productprice,2)
    response.write ("<td>") & (productprice) & ("</td>")
    response.write ("<td>") & RS.fields("modified_date") & ("</td>")
    response.write ("</tr>")
    RS.MoveNext
    loop
    RS.Close
    conn.Close

    %>
    SEMrush
     
    cogsworth12000, Dec 10, 2007 IP
    SEMrush
  2. urstop

    urstop Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    In the javascript function do this
    And in the ASP section where you have this
    add these lines of code before the first line of code
     
    urstop, Dec 11, 2007 IP