Now on SQLQuery

How can I update the results of a TQuery?

I have a DBGrid in Form2 connected to it, in form 1 I change the data the Query points to through a Table.

Did I make myself clear? :)

Let me explain, I have the query in Form2 to see just a range of records, those records change on the other Form (Form1) then I expect not to see some records again when I open Form2.

As always I'm in a hurry ha, ha!
chachoteAsked:
Who is Participating?
 
kretzschmarConnect With a Mentor Commented:
hi again,

seems i have misread the q

if you want a subset from the table or a subset from another table based on a field of the table, then add to your query-property datasource a datasource which is pointed to your table.

the sql-statement is then like:
select * from ATable where AField = :AFieldNameFromTheTable

there is also no need to close and open the query

meikl
0
 
rwilson032697Commented:
You will need to close and open the query again to get a new result set.

Cheers,

Raymond.
0
 
chachoteAuthor Commented:
guess what, I tried that before but the grid was empty... ┬┐when/where should I close and open the query again?
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
DrDelphiCommented:
if you have a query that is feeding form2's grid with a subset of Form1's grid data, then the logical place to re-run the query is whenever form1's data changes. So, if you do a delete to table1 (on form1), you would directly afterwards run
 Query1.Close;
 Query1.Open;

where Query1's SQL is the data subset from form1 and the dataset for form2. Does this make sense?


Good luck!!
0
 
DrDelphiCommented:
if you have a query that is feeding form2's grid with a subset of Form1's grid data, then the logical place to re-run the query is whenever form1's data changes. So, if you do a delete to table1 (on form1), you would directly afterwards run
 Query1.Close;
 Query1.Open;

where Query1's SQL is the data subset from form1 and the dataset for form2. Does this make sense?


Good luck!!
0
 
kretzschmarCommented:
hi chachote,

you need a live-query,
property requestlive = true

this works only on simple statements, without order-clause, joins, unions ...
also: select * from ATable

but there is no need to close and open the query

for more complex queries you need a TUpdateSQL-component as UpdateObject of your query (property)

this needs cachedUpdates=True and a bit code

here is also no need to close and open the query

meikl
0
 
IammeCommented:
You can use A datamodule and youcan use it from everywhere...........................you can write on all the events of the query that changes data........and out just

query.refresh;

whit a datamodule you said that all forms that are using that willl be cahnged an updated.........

bye......}
you
0
 
kretzschmarCommented:
hi iamme,

i guess you've misread this q,
and i wish you were more polite and do comment first

meikl
0
 
chachoteAuthor Commented:
too late for you, I already tried kretzschmar's answer... and is the best for me
0
 
chachoteAuthor Commented:
You got the idea !!! that's an answer, thank you "kretz". And thanks to all of you who tried.
0
All Courses

From novice to tech pro — start learning today.