Solved

ODBC from C++

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

920 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