views:

441

answers:

2

Hello, 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

+4  A: 

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;
Lieven
A: 

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?
n8wrl