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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VC++ ODBC COnnectivity to AS400 data 1

Status
Not open for further replies.

actdjohng

MIS
Apr 26, 2002
10
0
0
US
I need to create a desktop application reading data off the AS400 720 using VC++. Any ideas as to connect to the AS400? ODBC I know, but how? is the questions, never done it before.

 
if you add the line:

#include <afxdb.h>

to your stdafx.h file, you'll have access to all the MFC database connectivity functionality. You can then use CDatabase to connect:

CDatabase myDb;
if(myDb.Open(NULL))
{
//do stuff
}

You may want to make your CDatabase object a member of your application class, that way, you can access it from anywhere in the app by adding a get fuction to return a pointer to the database (GetDb(), or something like that).
CDatabase::Open(), when called with just NULL in the parameter list will display the standard ODBC connection dialog, allowing the user to select a datasource to connect to.
If you want to select the datasource from within the program, you'll need to do it the following way:

myDb.Open(lpszDSN, bExclusive, bReadOnly, lpszConnect, bUseCursorLib))

in this example, the parameters have the following values:
lpzDSN = &quot;&quot;
bExclusive = FALSE
bReadOnly = FALSE
lpszConnect = Connect string, something like &quot;ODBC;DSN=MyDsn...&quot; this will also contain things like username and password; it depends on the ODBC Driver and the database security
bUseCursorLib = FALSE

hope this helps

CMR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top