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.
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 = ""
bExclusive = FALSE
bReadOnly = FALSE
lpszConnect = Connect string, something like "ODBC;DSN=MyDsn..." this will also contain things like username and password; it depends on the ODBC Driver and the database security
bUseCursorLib = FALSE
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.