[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 319
  • Last Modified:

ODBC from C++

I need to create a program using Microsoft Deleveloper Studio in C++ that receives data from a messageing program (all sorted out) and then saves the records received in an Access Database. I am assuming that ODBC is the way to go, so can someone provide me with a simple code example to a) open a file b) delete records from the file c) write to the file and d) close the file
   Thanks
0
tgemini
Asked:
tgemini
1 Solution
 
nil_dibCommented:
You don't want to use MFC?
0
 
The_BrainCommented:
Go DAO, NOT ODBC, (too many hassles with ODBC) :^)

I can help you. (if you want MFC)  You would use the wizard.
0
 
tgeminiAuthor Commented:
Hmm... with most of my background being asm and more low level c kinda stuff I didn't know about these MFC or DAO. What are they, just librarys that I can use? And will they provide the functionality that I require. Any help is much appreciated.
0
 
pellepCommented:
here is a chunk of code using dao. must link with ddao35.lib in vc++

#include <afxole.h>
#include <dbdao.h>

CdbDBEngine dben;
CdbDatabase dbase;
cdbRecordset drec;
dbase = dben.OpenDatabase(lpszDBName);
sprintf(strSql, "SELECT * FROM %s", lpszTableName);
//open table lpszTable
drec = dbase.OpenRecordset(strSql, dbOpenDynaset); //using SQL
drec.AddNew();                            //make new record
drec.SetBookmark(drec.GetLastModified()); //and move there

//set value of field with index i to value lpszData
vInput=new COleVariant(_T((const LPCTSTR)lpszData),T_BSTRT);
drec.Fields[(int)i].SetValue(vInput);
drec.Update();

drec.Delete() //delete current record

drec.Close();
dbase.Close(); //close Recordset and Database


0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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