Mirror

An ADO replacement for SQL Explorer (Views: 100)


Problem/Question/Abstract:

Most programmers use the SQL Explorer which is installed by default with Delphi. With the announced extinction of the BDE, an alternative is needed for everyday’s common tasks. This is my solution.

How do I query an Access MDB File with ADO (no BDE installed)?

Answer:

The SQL Explorer has been for years one of the most important tools I used.
Now that I decided to shift from BDE solutions to ADO, I needed an alternative for the SQL Explorer which could gave me at least the same functionalities, so I created this little Delphi project (which I called ADO Explorer) which gaves me the main features a real programmer needs. In the next weeks I will prepare a second article in which I will explain how to customize and empower this program, makin it even a better solution that the Old, original, beloved SQL Explorer.

1. Open your Delphi 5 and create a new blank project.

2. On the form, drop these components:

An ADOConnection
An ADOQuery
A DBGrid
A DataSource
3 Buttons
A Memo component
An Edit component
An OpenDialog and SaveDialog component

3. Connect together the DB components (ADOConnection->ADOQuery->DataSource->DBGrid)

4. Insert in the first button’s OnClick Event handler this code:

procedure TForm1.Button1Click(Sender: TObject);
begin
  if ADOQuery1.Active then
    ADOQuery1.Close;
  if ADOConnection1.Connected then
    ADOConnection1.Connected := False;
  ADOConnection1.ConnectionString := Edit1.Text;
  ADOQuery1.SQL := Memo1.Lines;
  if UpperCase(Copy(Memo1.Lines[0], 1, 6)) = 'SELECT' then
  begin
    ADOQuery1.Open; // Result Set attended fro mthe operation
  end
  else
  begin
    ADOQuery1.ExecSQL; // No result set -> different method to open
  end;
end;

5. Insert in the second button’s OnClick Event handler this code:

if OpenDialog1.Execute then
  Memo1.Lines.LoadFromFile(OpenDialog1.FileName);

6. Insert in the third button’s OnClick Event handler this code:

if SaveDialog1.Execute then
  Memo1.Lines.SaveToFile(SaveDialog1.FileName);

7. Build & compile the project: the new ADO SQL Explorer is done!

The program can archive the most important queries used; it recognizes on its own the correct method to use with the given query and can be used against virtually every kind of OleDB or ODBC supported database.

The Sources of the program will be made available for download soon on my website (http://www.dreamscape.it) or can be asked directly by email to massimo.brini@dreamscape.it.

<< Back to main page