ch11lev1sec7

   

Creating Generic Database Applications

Many developers have had to deal with a requirement to create programs that work on a database or table specified at runtime. Most of the techniques for doing this with BDE programs are well known and well documented. Not so for the ADO components , but it is fairly simple to do these things after you know where to look.

Getting a Connection String from the User

Because connection strings are so complex and vary greatly between providers, it is fortunate that there is an undocumented function call that can help. This call is PromptDataSource() , which can be found in the ADODB.hpp include file provided with C++Builder, and it has the following signature:

 WideString PromptDataSource             (int theWindowHandle,WideString theOriginalConnectionString); 

This function presents the same dialog as displayed by the connection string property editor ”actually, it is the secondary dialog (from clicking Build) because the first dialog simply displays the string for manual editing. If you provide an original connection string, the dialog sets its controls accordingly so that the user is editing the connection string rather than creating it. Note that this is not a TADOConnection member ”it is a standalone function.

Getting Table Names

TADOConnection::GetTableNames() works essentially the same as TSession::GetTableNames() . It will update a supplied string list (that may, for instance, be the Items property of a TComboBox or TListBox ). Naturally, the connection must be open for this to work.

Getting Field Names

Field names are obtained in the same fashion as for BDE components ”by iterating through the TDataSet descendant's Fields property as follows :

 for (int Index = 0; Index < ADOTable->FieldCount; Index++)      Field = ADOTable->Fields->Fields[Index]->FieldName; 

Or, you can get a list of the names into a TStringList with the following:

 TADOConnection::GetFieldNames(TStringList *theList). 

Note that you must have previously allocated the list, or you can use a list such as that from a TComboBox or TListBox .

Getting Stored Procedure Names

Again, a bit of a secret here ” TADOConnection::GetProcedureNames (TStringList *theList) is the method you need to get the list of stored procedure names. Note that you must have previously allocated the list, or you can use a list, such as that from a TComboBox or TListBox .


   
Top


C++ Builder Developers Guide
C++Builder 5 Developers Guide
ISBN: 0672319721
EAN: 2147483647
Year: 2002
Pages: 253

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net