[ Pobierz całość w formacie PDF ]
.If you click either button you can see a list of thedrivers available on your system.FIGURE 8.13.The 32-Bit ODBC application.On my system one of the available drivers is called InterBase 4.X driver by Visigenic (*.gdb).If Iselected this button in the Add dialog, the dialog shown in Figure 8.14 would appear.FIGURE 8.14.The dialog used for configuring an ODBC connection.To set up a connection to the Employee.gdb table through the local InterBase server, I fill out the fieldsof the dialog, as shown in Figure 8.14.The database field of the dialog might have a path in it that lookslike this:c:\program files\borland\intrbase\examples\employee.gdbThe rest of the fields should look like this:Data Source Name: InterBase TestDescription: Test of InterBaseDriver: LocalDataBase: c:\program files\borland\intrbase\examples\employee.gdbUser Name: SYSDBAPassword: masterkeyYou should enter SYSDBA as the user name, and enter masterkey as the password.After entering all thisinformation, you should be able to connect to the table by pressing the Test Connect button.However, youmay not be able to run this test until you first press OK in the dialog, and then bring the dialog back up bypressing the Settings button from the main screen of the 32-Bit ODBC applet.If all is working correctly, you can now bring up the BDE Configuration utility that ships with BorlandC++Builder.On the drivers page pick New ODBC Connection to bring up the dialog for creating a newBDE connection, as shown in Figure 8.15.Fill in the fields as follows:SQL_Link_Driver: ODBC_Test2Default ODBC Drive: InterBase 4.x Driver by Visigenicfile:///D|/DOWNLOAD/charlie_calvert's_borland_c++_builder_unleashed/ch08.htm (19 of 20) [10/10/2000 1:13:00 AM]Ch 8 -- Database Basics and Database ToolsDefault Data Source Name: InterBase Test.After creating the driver for the ODBC test, switch to the Alias page of the BDE Configuration Utility.Select New Alias and type in ODBCTest1.Set the Alias type to ODBC_Test2.Click OK, save your workfrom the File menu, and exit BDECFG.exe.If BCB is already running, close it down.Now start up BCB and drop a TTable object on the main form.Select ODBCTest1 from the list of available aliases in the DatabaseName property.Now proceed asyou normally would, selecting a TableName and attaching a TDataSource and TDBGrid object to thetable.When prompted for a password, enter SYSDBA as the Username and masterkey as the password.If you want, you can relaunch the BDE configuration program and set the user name for this aliaspermanently to SYSDBA.In the summary presented here, I have hardcoded in the names of the various drivers and aliases you create.You can, of course, name the alias anything you want, just as you can enter whatever names you want inthe Data Source Name and Description fields of the ODBC Configuration dialog in the 32-Bit ODBCapplet from the Control Panel.FIGURE 8.15.The dialog for creating a new ODBC.connection.SummaryIn this chapter you have learned some of the fundamental facts you need to know to start accessingdatabases from BCB.In particular, you have learned about the following:The basics of using TTable and TQueryThe TDataModule objectThe SQL Monitor and Database ExplorerTCP/IP and ODBC connectivityNow that the groundwork has been laid, the next few chapters start digging into the objects that BCB usesto access databases.As a rule, this is not a particularly difficult subject, but there is a good deal ofinformation that needs to be covered.Once you have the facts that you need at your fingertips, you can start building real databases with BCB.C++Builder is one of the premier tools in the industry for accessing data, so you should be prepared to findyourself quickly writing powerful database applications that can be used by hundreds of people at one time.©Copyright, Macmillan Computer Publishing.All rights reserved.file:///D|/DOWNLOAD/charlie_calvert's_borland_c++_builder_unleashed/ch08.htm (20 of 20) [10/10/2000 1:13:00 AM]Ch 9 -- Using TTable and TDataSetCharlie Calvert's C++ Builder Unleashed- 9 -Using TTable and TDataSetIn this chapter, you learn some of the basics about accessing database tables using the TTable object.In particular, the chaptercovers the fundamental information you need to access tables without using SQL.An examination of using SQL to access tablesbegins in the next chapter.In the examples given here, you will be explicitly working with local Paradox tables, but nearly everything explained in this chapterapplies equally to dBASE files or to files located on a SQL server such as InterBase or Oracle.I decided to run these examplesagainst Paradox tables because I wanted to keep this chapter as simple as possible.Large portions of this book work exclusivelywith SQL databases, but this chapter sticks to the world of local tables.Looking a little more deeply at the content of this chapter, you can expect to find information on the following:The TTable object, which provides the fastest and simplest access to tables.The TQuery object, which is the gateway to the flexible and powerful world of SQL.The TDataSet object, an ancestor of TTable and TQuery, which provides the core functionality for accessing tables andthe records that lie within them.The TField object, which gives you access to the fields in a table or dataset.This object has powerful descendants such asTStringField and TIntegerField, all of which can be created automatically by a visual tool called the Fields Editor.The TDataSource object, which serves as an intermediary between data-aware controls and the TTable and TQueryobjects.The TDBGrid object, which provides a simple and easy way to display the contents of tables to the user.The TDBGridobject supports editing, deletion, and insertion.It also has support for drop-down lists in lookup fields, and the capability toassign colors to a column, row, or individual field.I visit this control more in Chapter 11, "Working with Field Objects."The TDBEdit component, which enables you to display a single field from a single record and to edit or insert the data forthat field.Filtering on nonkeyed fields.The TDatabase component, which can be handy when you need to optimize the way you connect to a server.Connecting to a database without using any visual tools.BCB supports something called two-way tools, which enable you todo things either visually or in code.Most of this chapter takes the visual route, but you can work entirely in code if you wantor if you have some special need that requires that approach.This chapter ends with a lengthy explanation of how to take thisrather unusual approach to BCB database programming.The order in which database events occur.This is an important subject, which has to be mastered by serious databaseprogrammers.Here is a second way to categorize some of the objects discussed in this chapter:Nonvisual: TTable, TQuery, TDataSet, TField, and TDatabaseVisual: TDBGrid and TDBEditLink (also nonvisual):TDataSourceThis latter view of the major database components breaks them down into two major categories.The nonvisual components enableyou to open, close, edit, and otherwise manipulate tables, records, and fields.The visual components display the tables to the user sohe or she can view or edit them
[ Pobierz całość w formacie PDF ]