Academic Tutorials



English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

VC++
VC++ Introduction
VC++ What's New
VC++ Supported Platforms
Visual C++ Settings
VC++ Breaking Changes
Visual C++ Walkthroughs
Visual C++ Editions
VC++ Project Templates
Visual C++ Guided Tour
VC++ Creating Command-Line Applications
VC++ Windows Applications
VC++ Reusable Code
VC++ Porting
VC++ Unix Users
VC++ Upgrade Wizard
VC++ Migration Primer
VC++ Managed Types
VC++ Member Declarations
VC++ Conversion Operators
VC++ Interface Member
VC++ Value Types
VC++ Boxed Value
VC++ General Language
VC++ Common Programming
VC++ Database Support
VC++ MFC Database Classes
VC++ Record
VC++ Record View
VC++ OLE DB Programming

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


MFC Database Classes (ODBC and DAO)


Previoushome Next









MFC Database Classes (ODBC and DAO)
A D V E R T I S E M E N T

Note:
Microsoft recommends using OLE DB or ODBC for new projects. DAO should only be used in maintaining existing applications.
Because MFC implements DAO and ODBC differently, the documentation for each class is almost completely separate. The DAO SDK is provided on the Visual C++ CDROM, and the ODBC SDK is provided on the MSDN Library CDROM. The following table lists the next topics to read if you are just beginning to study the MFC DAO classes or the MFC ODBC classes.

For more information, see the following topics:

  • ODBC and MFC
  • MFC Database Documentation
  • Using Database Classes with Documents and Views
  • Using Database Classes Without Documents and Views
  • Check the Microsoft Universal Data Access Web site at http://microsoft.com/data/ for updates to and news about ODBC and DAO.



MFC Database Documentation

The MFC documentation for DAO and ODBC classes consists of the components listed in the following table.
MFC Database Documentation
For documentation about See
Classes for both DAO and ODBC The class name in the MFC Reference
Global functions and macros for both DAO and ODBC The function or macro name in the MFC Reference
Programming with the MFC ODBC classes ODBC and MFC
Technical notes for both DAO and ODBC MFC Technical Notes



MFC Documentation and DAO Documentation

Throughout the MFC documentation for the MFC DAO classes, you will find references to topics in the DAO SDK documentation, included in the online documentation. Because MFC encapsulates (or wraps) DAO, the MFC documentation:

  • Focuses on MFC and how it differs from the underlying DAO implementation.
  • Points you to the DAO SDK Help topics for the underlying details. These cross-references are always worded as "topic X in DAO Help."
  • Points out differences where MFC does things differently from the way DAO does them. MFC does not wrap all of DAO. For example, MFC does not supply objects for DAO security functionality.
Note:
The DAO SDK Help is a separate Help file. There are no hypertext links from this documentation to DAO help in this version of Visual C++.
Note:
You might have to do some translating when you are browsing topics in DAO SDK Help. Examples in the primary DAO SDK documentation are written in the Basic programming language, not C++. (But the DAO SDK supplies a set of C++ examples that do not use MFC.)



MFC Documentation and ODBC Documentation

The MFC documentation for the MFC ODBC classes is organized differently. The MFC ODBC classes supply a high-level abstraction that rests on ODBC rather than a wrapper of the ODBC API. Therefore, the two documentation sets are less connected than are the MFC and DAO documentation sets. The ODBC documentation uses the C language, which is much closer to C++ than is Basic.




MFC: Using Database Classes with Documents and Views

You can use the MFC database classes � DAO or ODBC � with or without the document/view architecture. This topic emphasizes working with documents and views. It explains:
  • How to write a form-based application using a CRecordView or CDaoRecordView object as the main view on your document.
  • How to use recordset objects in your documents and views.
  • Other considerations.

For alternatives, see MFC: Using Database Classes Without Documents and Views.




Writing a Form-Based Application

Many data-access applications are based on forms. The user interface is a form containing controls in which the user examines, enters, or edits data. To make your application form based, use class CRecordView or CDaoRecordView. When you run the MFC Application Wizard and select ODBC client type on the Database Support page, the project uses CRecordView for the view class. The wizards no longer support DAO, so if you want to use CDaoRecordView, you have to code it manually.

In a form-based application, each record view object stores a pointer to a CRecordset or CDaoRecordset object. The framework's record field exchange (RFX) mechanism exchanges data between the recordset and the data source. The dialog data exchange (DDX) mechanism exchanges data between the field data members of the recordset object and the controls on the form. CRecordView or CDaoRecordView also provides default command handler functions for navigating from record to record on the form.

To create a form-based application with the application wizard, see Creating a Forms-Based MFC Application and Database Support, MFC Application Wizard.

For a full discussion of forms, see Record Views.




Using Recordsets in Documents and Views

Many simple form-based applications do not need documents. If your application is more complex, you probably want to use a document as a proxy for the database, storing a CDatabase or CDaoDatabase object that connects to the data source. Form-based applications usually store a pointer to a recordset object in the view. Other kinds of database applications store recordsets and CDatabase or CDaoDatabase object in the document. Here are some possibilities for using documents in database applications:

  • If you are accessing a recordset in a local context, create a CRecordset or CDaoRecordset object locally in member functions of the document or the view, as needed.

    Declare a recordset object as a local variable in a function. Pass NULL to the constructor, which causes the framework to create and open a temporary CDatabase or CDaoDatabase object for you. As an alternative, pass a pointer to a CDatabase or CDaoDatabase object. Use the recordset within the function and let it be destroyed automatically when the function exits.

    When you pass NULL to a recordset constructor, the framework uses information returned by the recordset's GetDefaultConnect member function to create a CDatabase or CDaoDatabase object and open it. The wizards implement GetDefaultConnect for you.

  • If you are accessing a recordset during the lifetime of your document, embed one or more CRecordset or CDaoRecordset objects in your document.

    Construct the recordset objects either when you initialize the document or as needed. You might write a function that returns a pointer to the recordset if it already exists or constructs and opens the recordset if it does not exist yet. Close, delete, and recreate the recordset as needed, or call its Requery member function to refresh the records.

  • If you are accessing a data source during the lifetime of your document, embed a CDatabase or CDaoDatabase object or store a pointer to a CDatabase or CDaoDatabase object in it.

    The CDatabase or CDaoDatabase object manages a connection to your data source. The object is constructed automatically during document construction, and you call its Open member function when you initialize the document. When you construct recordset objects in document member functions, you pass a pointer to the document's CDatabase or CDaoDatabase object. This associates each recordset with its data source. The database object is usually destroyed when the document closes. The recordset objects are typically destroyed when they exit the scope of a function.




Other Factors

Form-based applications often do not have any use for the framework's document serialization mechanism, so you might want to remove, disable, or replace the New and Open commands on the File menu. See the article Serialization: Serialization vs. Database Input/Output.

You might also want to make use of the many user-interface possibilities that the framework can support. For example, you could use multiple CRecordView or CDaoRecordView objects in a splitter window, open multiple recordsets in different multiple document interface (MDI) child windows, and so on.

You might want to implement printing of whatever is in your view, whether it is a form implemented with CRecordView or CDaoRecordView or something else. As classes derived from CFormView, CRecordView and CDaoRecordView do not support printing, but you can override the OnPrint member function to allow printing. For more information, see class CFormView




MFC: Using Database Classes Without Documents and Views

Sometimes you might not want to use the framework's document/view architecture in your database applications. This topic explains:
  • When you do not need to use documents such as document serialization.
  • Application wizard options to support applications without serialization and without document-related File menu commands such as New, Open, Save, and Save As.
  • How to work with an application that uses a minimal document.
  • How to structure an application with no document or view.



When You Do Not Need Documents

Some applications have a distinct concept of a document. These applications typically load all or most of a file from storage into memory with a File Open command. They write the updated file back to storage all at once with a File Save or Save As command. What the user sees is a data file.

Some categories of applications, however, do not require a document. Database applications operate in terms of transactions. The application selects records from a database and presents them to the user, often one at a time. What the user sees is usually a single current record, which might be the only one in memory.

If your application does not require a document for storing data, you can dispense with some or all of the framework's document/view architecture. How much you dispense with depends on the approach you prefer. You might:

  • Use a minimal document as a place to store a connection to your data source but dispense with normal document features such as serialization. This is useful when you want several views of the data and want to synchronize all the views, updating them all at once and so on.
  • Use a frame window, into which you draw directly, rather than using a view. In this case, you omit the document and store any data or data connections in the frame-window object.



Application Wizard Options for Documents and Views

The MFC Application Wizard has several options in Select database support, which are listed in the following table. If you use the MFC Application Wizard to create an application, all these options produce applications with documents and views. Some options provide documents and views that omit unneeded document functionality. For more information, see Database Support, MFC Application Wizard.


Option View Document
None Derived from CView. Provides no database support. This is the default option.

If you select the Document/view architecture support option on the Application Type, MFC Application Wizard page, you get full document support including serialization and New, Open, Save, and Save As commands on the File menu. See Applications with No Document.

Header files only Derived from CView. Provides the basic level of database support for your application.

Includes Afxdb.h. Adds link libraries, but does not create any database-specific classes. You can create recordsets later and use them to examine and update records.

Database view without file support Derived from CRecordView Provides document support but no serialization support. Document can store recordset and coordinate multiple views; does not support serialization or the New, Open, Save, and Save As commands. See Applications with Minimal Documents. If you include a database view, you must specify the source of the data.

Includes database header files, link libraries, a record view, and a recordset. (Available only for applications with the Document/view architecture support option selected on the Application Type, MFC Application Wizard page.)

Database view with file support Derived from CRecordView Provides full document support, including serialization and document-related File menu commands. Database applications typically operate on a per-record basis rather than on a per-file basis and so do not need serialization. However, you might have a special use for serialization. See Applications with Minimal Documents. If you include a database view, you must specify the source of the data.

Includes database header files, link libraries, a record view, and a recordset. (Available only for applications with the Document/view architecture support option selected on the Application Type, MFC Application Wizard page.)

For a discussion of alternatives to serialization and alternative uses for serialization, see Serialization: Serialization vs. Database Input/Output.




Applications with Minimal Documents

The MFC Application Wizard has two options that support form-based data access applications. Each option creates a CRecordView-derived view class and a document. They differ in what they leave out of the document.

Document Without File Support

Select the application wizard database option Database view without file support if you do not need document serialization. The document serves the following useful purposes:
  • It is a convenient place to store a CRecordset object.

    This usage parallels ordinary document concepts: the document stores the data (or, in this case, a set of records) and the view is a view of the document.

  • If your application presents multiple views (such as multiple record views), a document supports coordinating the views.

    If multiple views show the same data, you can use the CDocument::UpdateAllViews member function to coordinate updates to all views when any view changes the data.

You usually use this option for simple form-based applications. The application wizard supports a convenient structure for such applications automatically.

Document with File Support

Select the application wizard database option Database view with file support when you have an alternative use for the document-related File menu commands and document serialization. For the data-access portion of your program, you can use the document in the same way as described in Document Without File Support. You can use the document's serialization capability, for example, to read and write a serialized user profile document that stores the user's preferences or other useful information. For more ideas, see Serialization: Serialization vs. Database Input/Output.

The application wizard supports this option, but you must write the code that serializes the document. Store the serialized information in document data members.




Applications with No Document

You might sometimes want to write an application that does not use documents or views. Without documents, you store your data (such as a CRecordset object) in your frame-window class or your application class. Any additional requirements depend on whether the application presents a user interface.

Database Support with a User Interface

If you have a user interface (other than, for example, a console command-line interface), your application draws directly into the frame window's client area rather than into a view. Such an application does not use CRecordView, CFormView, or CDialog for its main user interface, but it normally use CDialog for ordinary dialogs.

Writing Applications Without Documents

Because the application wizard does not support creating applications without documents, you must write your own CWinApp-derived class and, if needed, also create a CFrameWnd or CMDIFrameWnd class. Override CWinApp::InitInstance and declare an application object as:
Copy Code
CYourNameApp theApp;

The framework still supplies the message-map mechanism and many other features.

Database Support Separate from the User Interface

Some applications need no user interface or only a minimal one. For example, suppose you are writing:
  • An intermediate data-access object that other applications (clients) call for special processing of data between the application and the data source.
  • An application that processes data without user intervention, such as an application that moves data from one database format to another or one that does calculations and performs batch updates.

Because no document owns the CRecordset or CDaoRecordset object, you probably want to store it as an embedded data member in your CWinApp-derived application class. Alternatives include:

  • Not keeping a permanent CRecordset or CDaoRecordset object at all. You can pass NULL to your recordset class constructors. In that case, the framework creates a temporary CDatabase or CDaoDatabase object using the information in the recordset's GetDefaultConnect member function. This is the most likely alternative approach.
  • Making the CRecordset or CDaoRecordset object a global variable. This variable should be a pointer to a recordset object that you create dynamically in your CWinApp::InitInstance override. This avoids attempting to construct the object before the framework is initialized.
  • Using recordset objects as you would within the context of a document or a view. Create recordsets in the member functions of your application or frame-window objects.


Be the first one to comment on this page.




  VC++ eBooks

No eBooks on VC++ could be found as of now.

 
 VC++ FAQs
More Links » »
 
 VC++ Interview Questions
More Links » »
 
 VC++ Articles
More Links » »
 
 VC++ News
More Links » »
 
 VC++ Jobs
More Links » »

Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: bsd programming language, bsd language programming tutorial pdf, history of bsd programming, basic bsd programming, bsd band satellite programming, syntax use in bsd programming, bsd programming software download, turbo bsd programming, bsd programming code, learn bsd programming

HTML Quizzes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizzes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright ? 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World | Important Websites
Copyright ? 2003-2024 Vyom Technosoft Pvt. Ltd., All Rights Reserved.