Featured

    Featured Posts

Database Connectivity in VC++ .

MFC supports two different kinds of database access :-
* Access via Data Access Object (DAO) and the Microsoft Jet Data engine.
* Access via Open Database Connectivity (ODBC) and an ODBC driver.

      A DAO database object, represent in MFC by class CDAODatabase, represents a connectionto a database through which we can operate on data.  We can have one or more CDaoDatabase objects active at a time in  given work space represented by a CDaoWorkspace object
In ADO
-- Each work space object contains a collection of open databases objects called database collection.
-- Each DAO database Objects contains collection of tabledefs, recordsets and relations.
      In MFC, access to a workspace's database collection is through member functions of class CDaoWorkspace.  Access to a database objects is through member functions of class CDaoDatabase.


Accessing ( Database object) without DAO

When we open a CDaoRecordset object without specifying an open CdaoDatabase object.  MFC implicitly creates a CDaoDatabase object along with the CDaoWorkspace that contains the database and underlying DAO database object
- The database object associated with a CDaoRecordset Object.
- The CDaoWorkspace object associated with a CDaoDtabase object.

 # Connecting to Database in VC++ ( using DAO )

       First of all create a database ( named db1) with a label ( named student ) in MS Access.  Now close the MS access application.
  • Create the VC++ application using MFC Appwizard
  • In step2 of Appwizard, ( in answer to the question what database support would you like to include) click the radio button labelled database view file support.
  •  Next, click the button labelled "Data Source" open the Database option box.
  • Select the DAO button, and then specify the database name as our data source, click ok.  When the select Database Table window appear click on select the table ( name student ) and then click on ok button.
  • Now, we click the ok button and the Finnish button in Appwizard, letting Appwizard to create the new program.
  • This creates a program whose view class based on the CDaoRecord view class, which in turn is based on CFormView class.
  • Open the main view, IDD_DB_FORM, in the dialog editor and add the controls we need two text boxes - one for name and other for grade and a button with the caption " Display the current record field".
      Using class wizard, we connect an event handler "OnButton1()" to the button and two member variables m-text1 and m-text2 to the text in the two text boxes.
      The program provides us with a pointer to the current recordset, m-set, so we can reach the name field as m-pset -> m-Name and the Grade field s m-pset -> m-Grade.  Suppose our project name is db, then
  void CDbview : : OnButton1()
{
  m-text1 = m-pset -> m-Name;
  UpdateData(false);
m-text2 = m-pset -> m-Grade;
  UpdateData(false);
}
Now the program is ready to run.

2 comments

Thanks for sharing such a nice article Sarkari Result your idea is mind blowing that's why i would like to appreciate your work.

Reply

Oh well thanks a lot for the appreciation dude..

Reply

Post a Comment

www.CodeNirvana.in

www.posthatke.com. Powered by Blogger.

Google+ Followers

Copyright © www.posthatke.com | Blogger Templates | Designed By posthatke.com