Hi there,
Yes, this is quite easy really.
I suggest you use the ADO (Active Data Objects) components in Delphi, since these are the most flexible.
There are only a few components you will need to allow you to do what you need. The TADOConnection, TADOQuery, TDataSource and TDBGrid (perhaps a TButton and a TComboBox too). With these you can open any database, discover and list all the tables with-in, and browse / insert / edit / delete data to your hearts content.
To achieve the basics, you need to:
1. Add a TButton and a TCombobBox to the bottom area of your Form1 (both controls located on the "Standard" tab).
2. Add a TDataSource component from the "Data Access" tab, and perhaps a TDBGrid from the "Data Controls" tab.
3. Add a TADOConnection and a TQuery component to your Form1 (located on the "ADO" tab)
4. Set the TDataSource.DataSet property to the name of the TADOQuery (ADOQuery1)
5. Set the TADOQuery.Connection property to the name of your TADOConnection (ADOConnection1)
6. Set the TDBGrid.DataSource property to the name of the TDataSource (DataSource1)
7. Set the TADOConnection.LoginPrompt property to False
8. Double-click your button (code window appears)
9. Make code look like the following:
procedure TForm1.Button1Click(Sender: TObject);
begin
//create a connection to a database
ADOConnection1.ConnectionString:=PromptDataSource(Self.Handle,ADOConnection1.ConnectionString);
try
//attempt to open the database
ADOConnection1.Open;
//retrieve table names, if opened
ADOConnection1.GetTableNames(ComboBox1.Items,False);
except
//oops! - there was an error, tell user
on e: Exception do raise e;
end;
end;
10. Double-click the ComboBox (code window appears)
11. Make code look like the following:
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
if ADOConnection1.Connected then
try
//attempt to open selected table
ADOQuery1.Close;
//create some basic SQL
ADOQuery1.SQL.Text:='SELECT * FROM '+ComboBox1.Text;
//open the table
ADOQuery1.Open;
except
//oops! - there was an error, tell user
on e: Exception do raise e;
end;
end;
12. Press 'F9' to compile and run the code.
Let me know if you need further help (mystic.smeg@yahoo.co.uk), but this will get you started.
na