0

I am trying to run SQL queries using a button click in Delphi, the database is successfully connected everything compiles fine when i enter the query i.e. "Select * from StaffDetails" and then click on run expecting it to show me the results in the DBGrid nothing happens at all the code for the button is as follows

procedure TForm1.Button1Click(Sender: TObject);
begin
  ADOQuery1.Close;
  ADOQuery1.SQL.Text := Memo1.Text;
  ADOQuery1.Open;
end;

I was thinking there would need to be some more in there, but watched several videos and this is all they seemed to have in there, so i am stumped for ideas. Everything else seems to be connected okay.

Any help is greatly appreciated.

Thanks Guys cant believe it was so simple have been sitting here since 9.30am and its now 14.37 lol must have fried my brain sitting here lol Thanks for your help guys much appreciated :)

Thanks in Advance Andy

1
  • Instead of adding a generic and anonymous "Thanks" section to your question you could have accepted one of the answers so others would know what particular hint actually solved your problem. Commented May 7, 2009 at 22:11

2 Answers 2

4

You have to

  • Connect the Grid to a TDatasource.
  • Connect the TDatasource to your ADOQuery1.

either in code or in the object inspector. In code this could be

Grid.DataSource = DataSource1;
DataSource1.DataSet := ADOQuery1;
Sign up to request clarification or add additional context in comments.

Comments

0

I am a Delphi noob, but things I would question:

  1. Is the button click event firing? I've mis-named a few event handlers in my time...
  2. Do you have to 're-bind' the grid to the updated query?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.