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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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
kretzschmarCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.