I want to insert a SQL query in a button. When clicked on button, the query should activate and display the database in a dbGrid.
To properly use SQL query in a button, first you need to make sure that everything is connected. Without connection to database, this isn't possible. You can assign the functions to make... the connection into the code then use:
procedure TForm1.Button1Click(Sender: TObject);
ADOQuery1.SQL.Text := Memo1.Text;
then in object inspector code add the following text:
Grid.DataSource = DataSource1;
DataSource1.DataSet := ADOQuery1;
This means that the Grid needs to be connected to the TDatasource and TDatasource to ADOQuery1.Read more