Solved

ODBC from C++

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

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!

Question has a verified solution.

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

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

696 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