Solved

How Can I Use The TQuery

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

832 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