Best Windows Hosting

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 27 August 2012

How to use TADOQuery in Delphi XE2?

Posted on 19:04 by Unknown
Following is the code snippet which will show you how to use ADOQuery in Delphi XE2?

function TClass1.UseADOQuery : integer;
begin
  try
    with qryADOQuery do
    begin
      Connection := ADOConnection; //Connection name
      Close;
      SQL.Clear;
      SQL.Text :=
        'SELECT ColumnX FROM TableA WHERE ' +
        'ColumnA = :ParameterA AND ' +
        'ColumnB = :ParameterB AND ' +
        'ColumnC = :ParameterC';

      Parameters.ParamByName('ColumnA').Value := ParameterA;
      Parameters.ParamByName('ColumnB').Value := ParameterB;
      Parameters.ParamByName('ColumnC').Value := ParameterC;
      Open;
      if (Recordcount = 0) then
        result := 0
      else
        result := Fields.FieldByName('ColumnX').Value; //Assume ColumnX value is an integer
      Close;
    end;
  except
    on E : Exception do
    begin
      result := 0;
      ShowMessage('Error occured in function UseADOQuery: ' + E.Message);
      exit;
    end;
  end;
end;

Explanation:First of all query has be be initialized with connection name. Now close it if already opened. For being on safer side, we should close it first before using it. Clear the SQL statement if any then write new SQL statement. Parameters to the query are passed by using colon (:) keyword. Recordcount keyword returns the number of rows affected.
Email ThisBlogThis!Share to XShare to Facebook
Posted in Delphi | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Frameset, Frame and IFrame Elements in HTML
    Frame Element With frames, you can display more than one HTML document in the same browser window. Each HTML document is called a frame, and...
  • Protecting E-mail Addresses on Webpages: Beware of using mailto protocol
    Placing an e-mail address on a Web page is a dangerous prospect nowadays. If the document on which the address appears generates even a medi...
  • Online Marketing Degrees
    Because global competition has become so intense, it should come as no surprise that companies invest heavily in their marketing and promoti...
  • Unix Commands which should be on tips of each developer
    General Commands: 1. date: shows date and time 2. history: lists the previously executed commands 3. man ls: shows online documentation by...
  • Online Music Degrees
    For those who want to pursue a music degree but find it difficult to do so because of time constraints, financial difficulties or physical l...
  • DOM Events: Mouse Events, Keyboard Events, Form Events, Frame Events and Touch Events
    Mouse Events 1. Click Event (onclick): The event occurs when the user clicks on an element. 2. Double Click Event ( ondblclick):  The event...
  • Never try to fake your Resume / CV
    It’s easy to dream up qualifications & work experience that you think will bolster your CV. But, the repercussions of faking facts can b...
  • What is DOM (Document Object Model): Tree and Node Structure of HTML Page
    The Document Object Model (DOM) defines a standard way for accessing and manipulating HTML documents. The DOM presents an HTML document as a...
  • Oracle Streams: An Overview
    Oracle Streams enables information sharing. Each unit of shared information is called a message. The stream can propagate information within...
  • How to grab the recruiter’s attention with your resume?
    Did you know that the average recruiter spends about 8 to 10 seconds glancing at your resume before s/he moves on to the next? So, whether y...

Categories

  • AJAX
  • C++
  • CSS
  • Delphi
  • DOTNET
  • HTML
  • Javascript
  • jQuery
  • Management
  • Online Degrees
  • Oracle
  • Others
  • Phonegap
  • PHP
  • Unix
  • XML

Blog Archive

  • ▼  2012 (155)
    • ►  September (64)
    • ▼  August (11)
      • How important is grooming in professional life?
      • 7 Questions to Ask in Your Appraisal Meeting
      • 5 ways to handle workload at your workplace
      • Interview Tips: How to get prepared for an interview?
      • Phonegap on Blackberry: 2 Programming Tips
      • How to use FindComponent function in Delphi XE2?
      • How to use TADOTable in Delphi XE2?
      • How to use TADOQuery in Delphi XE2?
      • OnShortCut event of Delphi XE2 Forms
      • Phonegap: An amazing combination of HTML5, CSS3 an...
      • Delphi 2010, Delphi XE and XE2: A comparison of fe...
    • ►  July (4)
    • ►  June (3)
    • ►  May (25)
    • ►  April (48)
Powered by Blogger.

About Me

Unknown
View my complete profile