Click here to Skip to main content
15,179,246 members
Articles / Database Development / SQL Server
Posted 17 Nov 1999


72 bookmarked

How to use RecordSets without using the AppWizard at the creation of your project.

Rate me:
Please Sign up or sign in to vote.
4.17/5 (18 votes)
17 Nov 19992 min read

All the books that I´ve read have the official chapter " Database programming", a little chapter in which there is the typical example of: Create a new project, with App wizard select the option use database and select what database will you use...

Ok, I begin my application, and one month later I realize "mmm...., I need one database for this project", or... " I need to add another Recordset to the database", or... " I need to add another database", must I begin again with my application? The answer is NO, and the solution is easy ( a dummy like me uses it, so it must be easy ;-) ).

Steps to do this:

  • Create a normal project without database support ( or if you have one created use that...).
  • In stdafx.h add this include:
    #include "afxdb.h"
  • In the class in wich you want to use the database ( for example in the View), add this member variable:
    CDatabase m_MyDatabase
  • When you init that class ( for example if we use the View in on Initial Update), init your database, calling
    (In which "os" is only a CString with the parameters to open your database, for example: CString os="ODBC;DSN=MyDb;UID=MyUser;PWD=MyPassword;") In this string we put:
    • ODBC (using ODBC database),
    • DSN=... The name of the datasource ( this is the name that you put when you add to the database the ODBC administrator your database),
    • UID=... Is the name of the user of the database,
    • PWD=... Is the password of that user.
  • Now we need an special recordset to get the data from our database. This is easy. Create a class ( with AppWizard ( Ctrl+W Key...), Add New Class), that inherits from CRecordSet then select your database and the table that you want to get from that database, and the fields that you need, ( you can create a lot of classes inherited from CRecordSet, as many "views" of your database as you need ( for example one recordset for each table or...).
  • Include the ".h" file of the recordset in the file in wich you are going to use it, and input variables of that recordset class in the classes that you need...
    CMyRecordSet *MyRecordSet; 
  • Then to open the recordSet:
    pMyRecordSet=new CMyRecordSet(&m_MyDatabase);
    pMyRecordSet->Open() // You can open it in many ways, see the help
  • Don´t forget when you exit from the program to close the database

And...,If you want to see more things, take a look at the help, this is only the starting point ( made by a dummy... :-) ).


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Braulio Dez
Web Developer
Spain Spain
Braulio is a developer specialized on Ms Technologies (Silverlight, ASP .net, SSRS, SSAS, SSIS). Currently he is working for Avanade in Málaga and as a journalist for the Spanish .net magazine Dotnetmania. He also is the webmaster of an specializad in .net technologies site, and Silverlight Based DB Schema Editor (

Comments and Discussions

GeneralSuper article Pin
danielthompson8521-Jun-09 2:01
Memberdanielthompson8521-Jun-09 2:01 
GeneralAbout the translation. Pin
greatghoul29-Mar-09 3:45
Membergreatghoul29-Mar-09 3:45 
GeneralRe: About the translation. Pin
Braulio Dez29-Mar-09 3:56
MemberBraulio Dez29-Mar-09 3:56 
Thanks !!!

About Database Programming, I have developed a free Silverlight base Databa Schema Editor:[DB Schema Editor]

Hope you like it


/// -------------------------
     Braulio Díez
     Free Silverlight based DB Schema Modeling Tool
/// -------------------------

GeneralRe: About the translation. Pin
greatghoul29-Mar-09 4:56
Membergreatghoul29-Mar-09 4:56 
QuestionHow to Connect two Clients which are in different LANs Pin
pengpcz17-Jan-08 22:35
Memberpengpcz17-Jan-08 22:35 
GeneralSynchronization Pin
ibelca5-Jun-07 7:01
Memberibelca5-Jun-07 7:01 
GeneralOn Database support Pin
swapna_signsin11-May-06 1:14
Memberswapna_signsin11-May-06 1:14 
QuestionHow do u get the data intothe edit boxes(Beginner) Pin
swapna_signsin7-Apr-06 3:45
Memberswapna_signsin7-Apr-06 3:45 
QuestionHow to use RecordSets without using the AppWizard at the creation of your project Pin
Ashwani_218-Jul-05 22:41
MemberAshwani_218-Jul-05 22:41 
QuestionHow to retrieve a integer or number Pin
Member 5715368-Sep-03 1:20
MemberMember 5715368-Sep-03 1:20 
GeneralClerical error! Pin
Pole23-Aug-02 18:52
MemberPole23-Aug-02 18:52 
QuestionWhere is the best place for CMyRecordSet *MyRecordSet? Pin
5-Apr-02 2:12
suss5-Apr-02 2:12 
AnswerRe: Where is the best place for CMyRecordSet *MyRecordSet? Pin
5-Apr-02 2:39
suss5-Apr-02 2:39 
GeneralRe: Where is the best place for CMyRecordSet *MyRecordSet? Pin
Carlos Antollini5-Apr-02 4:36
MemberCarlos Antollini5-Apr-02 4:36 
Generalnew article:) no HTML Pin
3-Apr-02 1:01
suss3-Apr-02 1:01 
GeneralRe: new article:) no HTML Pin
Braulio Dez26-Apr-02 2:17
MemberBraulio Dez26-Apr-02 2:17 
Generalnew article:) Pin
3-Apr-02 0:59
suss3-Apr-02 0:59 
Generalmore help Pin
3-Feb-02 8:56
suss3-Feb-02 8:56 
GeneralThanks Pin
feedback4-Oct-01 21:25
Memberfeedback4-Oct-01 21:25 
QuestionCDatabase :: How to?? Pin
Farah Mansor21-May-01 17:58
MemberFarah Mansor21-May-01 17:58 
AnswerRe: CDatabase :: How to?? Pin
<k>Andreas Hoheisel14-Aug-01 9:19
Member<k>Andreas Hoheisel14-Aug-01 9:19 
GeneralRegd DataBase Sample Pin
Prakash21-Mar-00 18:22
MemberPrakash21-Mar-00 18:22 
GeneralRe: Regd DataBase Sample Pin
Steven Gregg31-May-01 1:58
MemberSteven Gregg31-May-01 1:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.