Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get data from SQL table?

Status
Not open for further replies.

clifff

Programmer
Mar 22, 2002
20
MD
Hi! I use a TQuery to access a Paradox table. I want to perform a LIKE statement on table, From the help I saw:
Query1->SQL->Add("SELECT * FROM ....");
Query1->ExecSQL();

But how to get the results?
Didnt find anything from TQuery methods to get the data!!?

Anyone help...!


clifff
 
One way to get the data is to add a TDataSource and a TDBGrid. Connect the components by setting the DataSource property "DataSet" to the TQuery object-name, and then connect the DBGrid to the DataSource(using the DBGrid property DataSource).

(If you do not want to display the data, set DBGrid property Visable to false...;-) ) /Fredrik Eriksson
 
An other way would be to use TDataSet and its methods.

In this case such as:

An eaxmple for a Float value. More details see Help Pages.

A=Query1->FieldByName("Fieldname")->AsFloat..





hnd
hasso55@yahoo.com

 
Thanks ! If i use TDBgrid ,after a call to

Query1->SQL->Add("SELECT * FROM ....");
Query1->ExecSQL();
Will i have the result data in the Grid?

Will i have the results in the call to
A=Query1->FieldByName("Fieldname")->AsFloat..

??Still confused but hopefully i will found the answer!

clifff


 
If you use the DBGrid in the way I described earlier, you should have the data/result in the DBGrid.

I think I have some sample code if you´re interested(but it will take me a day to retrieve it). /Fredrik Eriksson
 
To use the second method you should do following sequence:

1. Initialize(open) the query. (May be by method SQL_Exec)
2. Position the Pointer to the Database (May be FindFirst(FindNext...)-Method)
3. Assign Result to a Variable:
example: float a;
A=Query1->FieldByName("Fieldname")->AsFloat..
A contains the result of that query
4. do next Operations;


.....

n.) Close query

What way you are choosing depends on your Application.

hnd
hasso55@yahoo.com

 
Thanks hnd & FredrikE ! I am new to the TQuery so every answer is a potential aplication! Thanks! i think i will work with the second method, because the data manipulation is made inside..

Sincerely,
cliff.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top