Solved

How Can I Use The TQuery

Posted on 1999-01-05
3
148 Views
Last Modified: 2010-04-04
Hello!!
I want to do query to a table. Can you show me some examples

Thanks...
0
Comment
Question by:mummi
3 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1354652
hi mummi,

an example,

  query1.sql.Clear; {Deletes the sql-statement of your query}
  query1.sql.add('Select * from Sampletable where Samplefield =' + Yoursamplevalue.asstring; {Add a sql-statement}
try
  query1.open; {opens the query}
except  
  {opening-error occured - your errorhandling}
end;

a datasource connected to the tquery and a dbgrid connected on the datasource and you will see the resultset of your query.
Can handled as a table, except writeback can only done with simple sql-statements (property requestlive = true).

another example

  query1.sql.Clear; {Deletes the sql-statement of your query}
  query1.sql.add('Delete  from Sampletable where Samplefield =' + Yoursamplevalue.asstring; {Add a sql-statement}
try
  query1.execsql; {execute sql-statement -> no resultset}
except  
  {execution-error occured - your errorhandling}
end;

this are simple examples, and if you know about sql, then you can do many things with tquery.

the sql-statementsyntax depends on the database, where you will do a query to the tables in it(paradox, oracle, access ...).

meikl
0
 

Accepted Solution

by:
mjustin earned 50 total points
ID: 1354653
with Query do
try
    // optional: for SQL server databases
    // if not Prepared then Prepare;
    Close; // in case it is already opened
    SQL.Text := 'your SQL commands go here';
    Open;
    // use it, print it...
finally
    Close;
end;
0
 

Author Comment

by:mummi
ID: 1354654
Thanks...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question