• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

Using ODBC with C++ and MFC

I am looking for an example of connecting to a Access database using ODBC to display existing records, and insert records. I know how to create the DSN what I do not understand is how to call the records and how/what to bind the records to so that they are visible in the dialog box. Also I used the wizard to create the ODBC stuff in the MFC application. For the main form CMyDBView I assume any code I would want to have exceute when the dialog box / form opens would go in the OnInitialUpdate() section. Does the code created by the wizard create any views that can be used?
0
martinjamesd
Asked:
martinjamesd
1 Solution
 
jkrCommented:
Check out http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample/html/_core_Databases_Samples.asp ("Databases Samples") - it lists all MSDN DB samples, including ODBC.
0
 
sreenu_v78Commented:
hai
Using CDatabase & CRecordset u can do
sample code like this

#include <afxdb.h>


CDatabase database;
database.OpenEx("DSN=dsnnamae");

//for insert data
CString query;
database.ExecuteSQL(query);


//for getting the records from data base
use recordset

CRecordset rs(&database);
rs.Open(CRecordset::dynaset,query);

go thru CRecordset Motheds in MSDN

best wishes
sreenu.
0
 
DanRollinsCommented:
hi martinjamesd,
Do you still need help with this?
-- Dan
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now