Solved

How Can I Use The TQuery

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

27 Experts available now in Live!

Get 1:1 Help Now