Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Window programming


Published on


  • Be the first to comment

Window programming

  1. 1. DAO(Data Access Object)DAO is familiar to database programmers using Microsoft Access Basic orMicrosoft Visual Basic. DAO uses the Microsoft Jet database engine (A databaseengine is the software in a DBMS that parses and executes SQL statements andaccesses the physical data) to provide a set of data access objects: databaseobjects, tabledef and querydef objects, recordset objects, and others. DAO worksbest with .mdb files like those created by Microsoft Access, but you can alsoaccess ODBC data sources through DAO and the Microsoft Jet database engine.Advantages of DAOEasy to use.Workspace level support. (A workspace is DAOs notion of a connection betweena user and a database. The workspace manages a list of databases that are active,and of individual users or groups of users who are known to use the workspace. )Both MFC and API provide DAO support.Speed is relatively faster than ODBC for jet database engine databases.Compatibility with the ODBC classes and with Microsoft Access Basic andMicrosoft Visual Basic.Ability to specify relations between tables.Databases You Can Access with DAO  Databases using the Microsoft Jet database engine, created with Microsoft Access or Microsoft Visual Basic, versions 1.x, 2.x, and 3.0 of the database engine.  Open Database Connectivity (ODBC) databases, including but not limited to Microsoft SQL Server, SYBASE SQL Server, and ORACLE Server. To access an ODBC database, you must have an appropriate ODBC driver for the database you want to access.  Microsoft Excel, versions 3.0, 4.0, 5.0, and 7.0 worksheets.  Text files. 1
  2. 2. ODBC  The ODBC interface is an industry standard and a component of Microsoft Windows Open Services Architecture (WOSA). The ODBC interface makes it possible for applications to access data from a variety of database management systems (DBMSs). ODBC permits maximum interoperability (The ability of one application to use the same code when accessing data in different DBMSs) -an application can access data in diverse DBMSs through a single interface. Furthermore, that application will be independent of any DBMS from which it accesses data. Users of the application can add software components called drivers, which create an interface between an application and a specific DBMS.  ODBC defines a standard set of functions for data access and carries a specification for which vendors can write drivers (A driver is a routine library that exposes the functions in the ODBC API. Drivers are specific to a single DBMS) that grant your application access to almost any of the databases currently available.Data SourceThe data source name represents a specific database or file that your ODBC application willaccess. The database may be comprised of many different tables, and once youre connected tothe data source you can access any object within it. • A data source is the data that the user wants to access and its associated operating system, DBMS, and network platform (if any).A data source name really is just that: a name. When you ask the driver manager to connectyou to a data source, it looks up the rest of the information it needs to get from your programon your machine to the data source, wherever and on whatever machine that information lives.ODBC specifies that each driver must implement a standardized set of SQL queries.ODBC also standardizes the API used to access the database, which means that the SQLcommands and the calls you use to express those commands are interpreted in a common styleby the driver. 2
  3. 3. Examples of data sources include a remote database running on Microsoft SQL Server across anetwork or a Microsoft Access file in a local directory.ODBC Layered ArchitectureODBC has a layered architecture. At the top, it starts with your application, which is written tocall the ODBC APIs. Your application requests that a data source be opened by specifying a datasource name configured by the user.The data source name provides the next layer, the driver manager, with enough information todo its work. The manager loads the appropriate ODBC driver and initializes it for a connectionto the data source youve named. The driver manager passes on any subsequent calls to theODBC API, from your application to the driver. The driver actually implements the call, doingthe work required to retrieve or accept data, or performing housekeeping chores.Databases You Can Access with ODBC 3
  4. 4. Using ODBC and the MFC ODBC classes, you can access any data source, local or remote, forwhich the user of your application has an ODBC driver. 16-bit, 32-bit, and 64-bit ODBC driversare available for a wide range of data sources. If you are working with a Microsoft Jet (.mdb)database, it is more efficient to use the DAO classes than the Microsoft Access ODBC driver.Advantages of ODBCEasy to use specially when developer are not familiar with COM environment.SQL support.Both API and MFC support.Good for relational databases only.DAO (Data Access Object)Data access objects are exactly what their name implies: a set of Automation objects that allowyour application to gain entry to different databases.Using DAO to work with native Microsoft Access databases provides the best performance .Creating Data SourcesWhen you start working with ODBC, youll always get started by using a data source.When you create a data source in your application, youre really only creating a link betweenthe actual data source and ODBC.Steps for setting up a default data source using ODBC 1. First step in creating an ODBC data source, as viewed through Control Panel, is to double-click on the ODBC icon. This will bring up the ODBC Data Source Administrator dialog box, as shown below: 4
  5. 5. 2. To create a new data source, just click the Add... Button ,Add Data Source Dialog Box will bedisplayed. Choose Microsoft Access driver from the list of drivers displayed & click on OK.ODBC Microsoft Set up Dialog box will appear which is shown below: 5
  6. 6. 3. Enter the data source name (that u’ve used in codes) and description and click on Select. 4. In the Select database dialog box , from the list of databases select database you have created. 5. Click on OK .you will return to previous dialog box of ODBC Microsoft Set up Dialog box .6. The data source has been set .Click Ok.Now ,you will see again the startup dialog box with your DSN . Click close to complete theprocess.Steps to create building a Database Application using ODBC using AppWizard 1. Select File | New. This opens the New Wizard. 6
  7. 7. 2. On the Projects tab, select MFC AppWizard (exe).3. Type a name for your project, such as Hello, in the Project Name field.4. Click OK. This causes the New Wizard to do two things: create a project directory (specifiedin the Location field) and then start the AppWizard.Steps to create application using AppWizard 1. In Step 1 of the AppWizard, specify that whether you want to create a Dialog-based application , SDI or MDI application. Click Next at the bottom of the wizard. 7
  8. 8. 2. In Step 2 of the AppWizard, the wizard asks you about a number of features that you can include in your application. Here we check the option for including support for database files in your application. Because we want to create any database application ,so check this box. Then we have to click on Data Source button to select data source which we have created. 8
  9. 9. 3. In Step 3 of the AppWizard, the wizard asks you about a number of features that you can include in your application. You can uncheck the option for including support for ActiveX controls if you will not be using any ActiveX controls in your application. Because you wont be using any ActiveX controls in todays application, go ahead and uncheck this box. 9
  10. 10. 4. In Step 4 of the AppWizard, the wizard asks you about a number of features that you can include in your application. You can check or uncheck the features which you do not want or want in your application. Click Next at the bottom of the wizard to proceed to the next AppWizard step. 10
  11. 11. 5. In Step 5 of the AppWizard, leave the defaults for including source file comments and using the MFC library as a DLL. Click Next at the bottom of the wizard to proceed to the final AppWizard step. 11
  12. 12. 6. The final step of the AppWizard shows you the C++ classes that the AppWizard will create foryour application. Click Finish to let AppWizard generate your application shell.Before AppWizard creates your application shell, it presents you with a list of what it is going toput into the application shell, based on the options you selected when going through theAppWizard. Click OK and AppWizard generates your application.DAO vs ODBC 12
  13. 13. DAO ODBC1. Data Access Object Open Data Base Connectivity2. DAO is an object-oriented ODBC is a call-oriented API .database programming model.3. DAO allows you to open a ODBC doesn’t.database and directly perform datadefinition language calls .4. DAO enforces the notion of When you use ODBC to connect to aconnecting to a database as an database, youre connected directobject. When you use DAO, youll to the database and youre ready toask it to get connected to the work with its data.database and use a workspaceobject to manipulate the databaseitself, i.e. the configuration of thedatabase and its tables, indexesand other entities.5. Speed is relatively faster than Speed is slowerODBC for jet database enginedatabases.6. DAO is best choice when you ODBC is for various type ofhave DAO components installed on database which provides ODBCyour machine and you are using drivers such as SQL Server, Oracle,Microsofts jet database engine MS-Access. for connecting tobased databases such as MS-Access, different databases no matter howSQL Server, MS-Excel or Paradox. big they are - from tiny text files to large databases. 13
  14. 14. 7. DAO can manipulate ODBC ODBC can manipulate ODBC datadatabases. But it is less efficient for bases much efficiently.this task becoz it is best used with.mdb database files.8. DAO classes in MFC only two ODBC classes in MFC onlyclasses CDaoDatabase and represent two classes: CDatabaseCDaoRecordset . and CRecordset.9. System implements DAO System implements ODBC librarieslibraries as COM objects. as a set of DLLs.10. DAO best suited for application If your application using otherthat manipulate .mdb and other file database now and will using otherformats are FoxPro and Excel. So database in future then using ODBCapplication that use Microsoft is beneficial.Access and always using it ,thenyou use DAO.11. DAO classes provide more But in ODBC , many functions arepowerful set of methods that can not defined in ODBC which areuse to manipulate database defined in DAO .without having to write a lot ofcomplicated code or SQLstatements.13. DAO is only interested in ODBC connects to a data source.connecting to databases. 14
  15. 15. 14. A DAO program would have to The users of an ODBC program canbe written to be configurable get to the Control Panel andbefore you could change the reconfigure their data source list todatabase you were working with. point at a different database without any trouble at all. This fact makes ODBC somewhat more scaleable and far more manageable than DAO.15. DAO is more efficient at ODBC is less efficient at accessingaccessing the native file formats it that same data through thesupports than ODBC appropriate driver.16. Under DAO, dynamic recordsets Under ODBC, snapshot recordsetsare the default. are the default .17. DAO to be less efficient than More efficient than DAO.ODBC when trying to access aremote server .Similarities between DAO and ODBCODBC and DAO both can manipulate ODBC data sources. However, DAO is less efficient at thistask because its best used with .mdb database files.AppWizard can create a basic database application based on either the ODBC or DAO classes.Which type of application you want to create depends, at least in some part, on the type ofdatabases with which you will be working.ODBC and DAO both use objects of an MFC database class to provide a connection to thedatabase being accessed. In ODBC, this database class is called CDatabase, whereas in DAO, theclass is called CDaoDatabase. Although these classes have different names, the DAO databaseclass contains some members similar to those found in the ODBC class. 15
  16. 16. Similarities between DAO and ODBCODBC and DAO both use objects of a recordset class to hold the currently selected records fromthe database. In ODBC, this recordset class is called CRecordset, whereas in DAO, the class iscalled CDaoRecordset. Although these classes have different names, the DAO recordset classcontains not only almost the same members as the ODBC class but also a large set of additionalmember functions.ODBC and DAO use similar procedures for viewing the contents of a data source. That is, in bothcases, the application must create a database object, create a recordset object, and then callmember functions of the appropriate classes to manipulate the database.Choosing Between MFC DAO and ODBC Classes 16
  17. 17. Can I With DAO classes? With ODBC classes?Access .MDB files YES YESAccess ODBC data YES YESsourcesAvailable for 16 Bit YESAvailable for 32 Bit YES YESAvailable for 64 Bit YESDatabase engine Microsoft Jet database Target DBMSsupport engineDDL support YES Only through direct ODBC callsDML support YES YESNature of the MFC "Wrapper" of DAO core Simplified abstractionimplementation functions rather than a "wrapper" of the ODBC APIOptimal for .mdb files (Microsoft Any DBMS for which Access) you have a driver, especially in client/server situations 17