Cheap Hosting Domain Names

  • 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

  • Online Religion Degrees
    Religion plays a major role in the historical, political, and cultural life of our societies. If you are fascinated by belief systems, consi...
  • How to create dynamic tables in HTML using javascript at runtime?
    In this tutorial, you will come to know how to create dynamic tables in HTML. There are some situations when you don't know the contents...
  • Online Economics Degrees
    Economists research and analyze economics, or the way people choose to use their resources to produce goods and services. Economists typical...
  • Online Advertising Degrees
    The objective of any business firm is to market and sell its products or services profitably. In small firms, the owner or chief executive o...
  • Online Geography Degrees
    With the growth of online colleges and universities, geography degrees online have gained immense importance. Geography degrees online can b...
  • Online DBA (Database Administrator) Degrees
    Database managers keep vital information organized.  With a database technology degree, you may find yourself organizing customer informatio...
  • Online Social Science Degrees
    Social science covers a broad range of fields: behavioral science, history, economics, geography, political science, women''s studie...
  • Difference between page_init, page_load and page_prerender events
    page_init This event is the first event to occur when an ASP.NET page is executed. This is the event where you should be performing any init...
  • Online BCA Degrees
    The boom in the IT industry has opened up plenty of job opportunities for computer professionals. As a result, computer application courses ...
  • Online Professional Degrees
    Going back to get more education can be a difficult, time consuming and sometimes impossible proposition. But with new advances in virtual t...

Categories

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

Blog Archive

  • ▼  2012 (180)
    • ►  September (89)
    • ▼  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