Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataBase & C++ 1

Status
Not open for further replies.

swaroop

Programmer
Joined
Feb 4, 2001
Messages
100
Location
US
Hi All,

I wanted to learn to access database through C++ programming.Unfortunetly I only have Ms-Access in my system. Can any one send some sample programms to access data from MS-Access database so that I can learn it easly. I have Bcc32(Borland) compailer.

If you have sample code you please forward to swaroop67@hotmail.com


Regards,

Swaroop.
 
This code is the basical code of ODBC API. It is easy to learn and to understand. I didn't put there the errors handling.

#include<sql.h>
char* DSN =&quot;Driver={Microsoft Access Driver(*.mdb)};
DBQ=c:\\temp\\sample.mdb&quot;;
int main()
{
HENV hEnv;
SQLAllocEnv(&hEnv);
HDBC hDbc;
SQLAllocConnect(hEnv,&hDbc);
SQLDriverConnect(hDbc,NULL,)
SQLDriverConnect(hdbc, hwnd,
(SQLTCHAR*)DSN, SQL_NTS,NULL,
0,0, SQL_DRIVER_NOPROMPT);
HENV hEnv;
SQLAllocEnv(hDbc,&hEnv);
SQLExecDirect(hEnv,&quot;delete* from OneTable&quot;,SQL_NTS);
SQLFreeEnv(Env);
SQLDisconnect(hDbc);
SQLFreeConnect(hDbc);
SQLFreeEnv(hEnv);
} John Fill
 
For an easier database program, and more common (in my opinion, this is not designed to invite or promote flames) see for a good alternative.

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top