Title: An ADO replacement for SQL Explorer Part I
Question: 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 everydays 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 buttons 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 buttons OnClick Event handler this code:
if OpenDialog1.Execute then
Memo1.Lines.LoadFromFile(OpenDialog1.FileName);
6. Insert in the third buttons 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.
In the next Part (coming soon) we will see how to give the user the chance to memorize to most recently used ConnectionStrings and Queries, and how to save the resulting datasets in text files.
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.
==========================
Massimo Brini Dreamscape
==========================
Located in Northern Italy near Lecco, Massimo Brini is a Freelance Consultant and Developer. Among his customers you can find Borland, Corel, Microsoft and many other notable software and hardware vendors. If you need help, dont hesitate to contact us at massimo.brini@dreamscape.it
Massimo Brini un Consulente e Sviluppatore Freelance; tra i suoi clienti annovera Borland, Corel e Microsoft, oltre ad altri nomi prestigiosi del panorama informatico.
Ha partecipato con Borland e Corel allo SMAU 2000, aprendo le sessioni per programmatori come oratore sulle tematiche Sviluppo di Applicazioni WEB con Delphi e ADO: fondamenti logici ed evidenze empiriche. Se siete in difficolt e avete necessit di consulenza, con particolare riferimento a tematiche di conversione da BDE a ADO o Interbase, a tecniche di sviluppo Internet, non esitate a contattarci presso lindirizzo email massimo.brini@dreamscape.it