Solved

How Can I Use The TQuery

Posted on 1999-01-05
3
144 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now