Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 4 - The ADOQuery Component
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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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? 
DELPHI-KYLIX

The ADOQuery Component
By: Jacques Noah
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2006-10-09

    Table of Contents:
  • The ADOQuery Component
  • ADOQuery Component
  • A Practical Example
  • Dynamic Queries

  • 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


    The ADOQuery Component - Dynamic Queries


    (Page 4 of 4 )

    A dynamic query gives you flexibility in retrieving data from a table. For example, say you want to retrieve all the people in the database with the surname of Smith. You are going to use a parameterized query:

    SELECT * from person WHERE surname=:parameter

    The parameter acts as a placeholder for a value in the WHERE clause of a SQL statement. So you need to provide a value for this parameter, like so:

    SELECT * from person WHERE surname=:parameter

    q1.Parameters.ParamByName('parameter').text:='Smith';

     

    You can use as many parameters as you like, just make sure to give them the values as above.

    Let’s put this in practice. Double click on the button and add the following code:

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    q1.Close;
    q1.SQL.Add(memo1.Lines.Text);
    q1.Parameters.ParamByName('parameter').text:='Smith';
    q1.Open;
    q1.First;
    while not q1.Eof do begin
    memo2.Lines.add(q1.FieldByName('name').Text+ '
    '+q1.FieldByName('surname').Text);
    q1.Next;
    end;
    end;

    The parameter value in this case is "Smith." Once the "q.open" code is executed, the results of the query will be ready to be displayed. The while loop runs until the end of the file and at the same time adds the results in the memo1:

     while not q1.Eof do begin
    memo2.Lines.add(q1.FieldByName('name').Text+ '
    '+q1.FieldByName('surname').Text);
    q1.Next;
    end;

     

    The "q1.next" simply moves the pointer to the next record.

    In memo1 type the following SQL statement:

    select name, surname from person WHERE surname=:parameter

    Here’s a sample run:

    Conclusion

    In the next article we are going to discuss creating reports with ADO. This will give you the complete set of knowledge that you need to produce really productive and useful database applications.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · I hope you found my article educational; I welcome your comments.
       · I have read through your articles.It's helpful since i'm new to Delphi.But I found...
     

    DELPHI-KYLIX ARTICLES

    - Loading an XML Document into the DOM
    - Delphi Wrapper Classes and XML
    - Delphi and the DOM
    - Delphi and XML
    - Internet Access: Client Service
    - Finishing the Client for an Internet Access ...
    - The Client for an Internet Access Control Ap...
    - User Management for an Internet Access Contr...
    - Important Procedures for an Internet Access ...
    - Server Code for an Internet Access Control A...
    - Constructing the Interface for an Internet A...
    - Building a Server Application for an Interne...
    - Building an Internet Access Control Applicat...
    - Client Dataset: Working with Data Packets an...
    - Using the Client Dataset in an N-Tiered Appl...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT