0% found this document useful (0 votes)
44 views

ODBC Connectivity

The document outlines 11 steps to create a database application using ODBC: 1) Create a table using MS Access or another tool and configure an ODBC data source to point to the new database. 2) Create an MFC application in Visual Studio with database support and select the ODBC data source. 3) Comment out a security issue line in the application code. 4) Add controls to the application dialog and associate variables to the controls for retrieving database fields. 5) Add code to button click handlers for adding, deleting, and updating database records.

Uploaded by

Karthik Ram
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

ODBC Connectivity

The document outlines 11 steps to create a database application using ODBC: 1) Create a table using MS Access or another tool and configure an ODBC data source to point to the new database. 2) Create an MFC application in Visual Studio with database support and select the ODBC data source. 3) Comment out a security issue line in the application code. 4) Add controls to the application dialog and associate variables to the controls for retrieving database fields. 5) Add code to button click handlers for adding, deleting, and updating database records.

Uploaded by

Karthik Ram
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Steps to create a Database Application using ODBC

1. Create a Table using MS-Access or any other tool preferable for you.
2. Configure an ODBC data source to point to the database just created by running
the ODBC Administrator, present in the Control Panel on your computer as
follows.
a. Control panel  Administrative Tools  Data Sources (ODBC)  Add
 Select an appropriate driver  Finish  Give a suitable data source
name and description  Click Select  Select and point the database to
the database you just created  finish the task by giving Ok and exit the
control panel

b. Open Visual Studio  Create an MFC application  Give name 


Application type SDI in next screen  next  next  Choose Database
view with file support  Client type ODBC  Choose Dynaset /Snapshot
(Dynaset is default)  Click datasource  Choose machine datasource
tab  select the database created by you and click ok  give user name
and password (if required)  Ok  Tables are listed  choose the
required table  Next  Next (accept the default values unless required)
view the classes created (View, App, Doc, Frame and Set are created)
 Give Ok for the security warning message box.

3. Go to your *****Set.cpp in your solution explorer and comment out the #error
Security Issue line.

4. Go to Resources  decompress the main icon  decompress your .rc project


folder  decompress dialog  choose IDD_<your project name>_Form

5. In the dialog frame displayed, place the required controls (static and edit controls
etc.,) using the tool bar and save the form. Have buttons for adding, deleting,
updating records.

6. In the solution explorer  <your project name>View.cpp

7. In the DoDataExchange(CDataExchange* pDX), add the lines for associating the


variable to the control as illustrated in the comment lines in the function
for e.g.,

DDX_FieldText(pDX, IDC_MYEDITBOX, m_pSet->m_szColumn1, m_pSet);

8. In the above e.g., m_szColumn1 is the variable which holds a particular field of
the database. This can be obtained from <your project name>Set.h file in the
solution explorer

9. Save the project after adding the required no of DDX lines (depending on the no
of controls you have on the form).

Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
10. Double click the button for adding records  this takes you to the message
handler

E.g., For adding:

void CstudentodbcView::OnBnClickedButton2()
{
// TODO: Add your control notification handler code here
if(m_pSet->CanAppend())
{
m_pSet->AddNew();
UpdateData(TRUE);
m_pSet->Update();
m_pSet->Requery();
m_pSet->MoveLast();

}
else
AfxMessageBox(_T("Not possible"));
}

For Deletion:

void CstudentodbcView::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
m_pSet->Delete();
m_pSet->MovePrev();
m_pSet->Requery();
UpdateData(FALSE);
}

For Editing:

void CstudentodbcView::OnBnClickedButton3()
{
// TODO: Add your control notification handler code here
m_pSet->Edit();
m_pSet->Update();
UpdateData(TRUE);
m_pSet->Update();
m_pSet->Requery();
}

11. Compile and Run the Application.

********

Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy