ASP
  Home arrow ASP arrow Page 5 - Grabbing Data On The Fly
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Grabbing Data On The Fly
By: Phanix Chen
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2001-12-08

    Table of Contents:
  • Grabbing Data On The Fly
  • Some methods for passing data around
  • Using frames to solve the refresh problem
  • Query and return
  • The processframe.asp page
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Grabbing Data On The Fly - The processframe.asp page


    (Page 5 of 6 )

    Our processframe.asp page contains a fairly large amount of code, so I will just describe the function that will generate our query results, GetQueryResults(). You can, of course download the source code for this entire article from the last page.

    GetQueryResults() is an ASP function that takes one parameter. Its prototype is shown below:

    sub GetQueryResults(strKeyword)

    The strKeyword parameter is collected from the Request.QueryString variable, which is passed to the page from the “MainFrame” frame, as shown below:

    dim authorQuery

    authorQuery = Request.QueryString("authorQuery")



    if authorQuery <> "" then

    GetQueryResults(authorQuery)

    end if


    As you can see, if there is no query passed to the page, then it will do nothing. This is handy, because when our frameset is loaded initially, the processquery.asp page won’t have any authorQuery value passed in the query string.

    Our GetQueryResults() function starts by declaring a new ADO command and a new ADO recordset object. Then, a connection to the SQL server is established. In this example, I am assuming that SQL Server resides on the same machine as IIS:

    sub GetQueryResults(strKeyword)



    dim objConn

    dim objRS

    dim counter



    set objConn = Server.CreateObject("ADODB.Connection")

    set objRS = Server.CreateObject("ADODB.Recordset")

    counter = 0



    objConn.Open "Provider=SQLOLEDB; Data Source=(local); Initial Catalog=pubs; User Id=sa; Password="

    objRS.ActiveConnection = objConn


    Next, we open our recordset object with a query. The query uses the LIKE function to test whether each author’s last name (the au_lname field) is like the strKeyword variable:

    objRS.Open "SELECT au_id, au_fname+' '+au_lname AS au_name FROM authors WHERE au_lname LIKE '%" & strKeyword & "%'"

    We’re now ready to create our JavaScript function, which will add the details of each author found to the authors drop down box in the “MainFrame” frame:

    function ShowResults()

    {

    var numItems = top.MainFrame.form1.bookAuthor.length;



    for(i = numItems - 1; i >= 0; i--)

    top.MainFrame.form1.bookAuthor.options[i] = null;


    Our ShowResults() JavaScript function starts by removing all of the items in the main frames author drop down list.

    If no records in the authors’ table matched our keyword(s), then the JavaScript function will add an option to the main frames author drop down list telling the user that no records were found:

    <%

    if objRS.EOF then

    %>

    top.MainFrame.form1.bookAuthor.options[0] = new Option();

    top.MainFrame.form1.bookAuthor.options[0].text = "-- No Authors Found --"


    On the other hand, if at least one author matched our keyword(s), then we add the details of each author to the main frames author drop down list:

    while NOT objRS.EOF

    %>

    top.MainFrame.form1.bookAuthor.options[<%=counter%>] = new Option();

    top.MainFrame.form1.bookAuthor.options[<%=counter%>].text = "<%=objRS("au_name")%>";

    top.MainFrame.form1.bookAuthor.options[<%=counter%>].value = "<%=objRS("au_id")%>";

    <%

    counter = counter + 1

    objRS.MoveNext

    wend

    %>


    If, for example, we enter “e” in the query text box and click on the query button, 18 results will be added to our author drop down list.

    Querying our authors table and returning results

    On the other hand, if we entered “blahblah” into the query text box and clicked on the query button, then no results would be returned.

    Our add book form when no results are returned

    More ASP Articles
    More By Phanix Chen


     

    ASP ARTICLES

    - Central Scoreboard with Flash and ASP
    - Calorie Counter Using WAP and ASP
    - Creating PGP-Encrypted E-Mails Using ASP
    - Be My Guest in ASP
    - Session Replacement in ASP
    - Securing ASP Data Access Credentials Using t...
    - The Not So Ordinary Address Book
    - Adding and Displaying Data Easily via ASP an...
    - Sending Email From a Form in ASP
    - Adding Member Services in ASP
    - Removing Unconfirmed Members
    - Trapping HTTP 500.100 - Internal Server Error
    - So Many Rows, So Little Time! - Case Study
    - XDO: An XML Engine Class for Classic ASP
    - Credit Card Fraud Prevention Using ASP and C...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway