Question:
How to use database/tables of an unknown format using Delphi/Pascal?
anonymous
2011-03-22 02:20:05 UTC
We've been given a database assignment in 'generic programming' class, to write a program using Delphi that will open & use any unknown database with unknown quantity of table/s. So, the idea is to allow a user to open any database, select table/s from a list, then browse / edit / delete data. Is that possible? - Please help!
Three answers:
mystic smeg
2011-03-22 02:57:58 UTC
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
riggles
2016-12-28 11:45:44 UTC
PowerISO is a CD/DVD image record processing gadget, which permits you to open, extract, create, edit, compress, encrypt, chop up and convert ISO documents, and mount those documents with inner electroniccontinual. it may technique basically about all CD-ROM image documents which incorporate ISO and BIN. DAA is a format for a picture record, which helps some stepped forward helpful components, which incorporate compression, password secure practices, and splitting to dissimilar volumes (resembling .RAR and different compression formats). ..... So there is not any obtainable record conversion application which you could use to transform this record to an MP3 CHEERS!!!
Mighty Matt
2011-03-22 02:32:24 UTC
Why not:



show tables (to get list of tables)

describe each table in that list (to get schema)

Parse the schema, then build your program from that output.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Search results for 'How to use database/tables of an unknown format using Delphi/Pascal?' (Questions and Answers)
5
replies
what are programming languages?
started 2007-11-14 02:15:22 UTC
programming & design
Loading...