Solved

ODBC from C++

Posted on 1999-01-18
4
257 Views
Last Modified: 2012-06-27
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
Comment
Question by:tgemini
4 Comments
 
LVL 4

Expert Comment

by:nil_dib
ID: 1184490
You don't want to use MFC?
0
 
LVL 1

Expert Comment

by:The_Brain
ID: 1184491
Go DAO, NOT ODBC, (too many hassles with ODBC) :^)

I can help you. (if you want MFC)  You would use the wizard.
0
 

Author Comment

by:tgemini
ID: 1184492
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
 
LVL 4

Accepted Solution

by:
pellep earned 100 total points
ID: 1184493
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now