Solved

ODBC from C++

Posted on 1999-01-18
4
291 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

840 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