I am just starting out in trying to access a MS Access Database from DEV C++. I have the database all set up and I am trying to read the data/ The problem is that there are errors which I do not understand.
The error readsCode:#include <windows.h> #include <sqlext.h> #include<sql.h> #include <stdio.h> int main(void) { HENV hEnv = NULL; //for allocating memory usingSQLAllocEnv HDBC hDBC = NULL; //connection handle HSTMT hStmt = NULL; // statement handle UCHAR szDSN[SQL_MAX_DSN_LENGTH] = "Directory"; UCHAR* szUID = "SomeUsername"; //username of the database UCHAR* szPasswd = "SomePassword"; //password of the database CHAR szModel[128]; SDWORD cbModel; UCHAR szSqlStr[] = "Select * From Students"; //Students is the table name in my database RETCODE retcode; int i, j,no=1; // Allocate memory for ODBC Environment handle SQLAllocEnv (&hEnv); SQLAllocConnect (hEnv, &hDBC); //connecting to the database retcode = SQLConnect(hDBC,szDSN,SQL_NTS,szUID,SQL_NTS,szPasswd,SQL_NTS); //”retcode” will hold ‘1’ if connection is established else ’-1’ printf("Connecting to the database\n"); for(i=0;i<10;i++) { for(j=0;j<100;j++); printf("."); } if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) { retcode = SQLAllocStmt (hDBC, &hStmt); retcode = SQLPrepare (hStmt, szSqlStr, sizeof (szSqlStr)); retcode = SQLExecute (hStmt); printf("\nReading the records\n"); SQLBindCol(hStmt, no, SQL_C_CHAR, szModel, sizeof(szModel), &cbModel); SQLBindCol(hStmt, no+1, SQL_C_CHAR, szModel1, sizeof(szModel1), &cbModel1); retcode = SQLFetch (hStmt); while (retcode == SQL_SUCCESS || retcode ==SQL_SUCCESS_WITH_INFO) { printf ("\t%s\n", szModel); retcode = SQLFetch (hStmt); } SQLFreeStmt (hStmt, SQL_DROP); SQLDisconnect (hDBC); } else { printf("Cannot read the database\n"); } SQLFreeConnect (hDBC); SQLFreeEnv (hEnv); return 0; }
11 invalid conversion from `const char*' to `UCHAR*'
40 `szModel1' undeclared (first use this function)
40 `cbModel1' undeclared (first use this function)
Is there any other way to query a database using C++?



LinkBack URL
About LinkBacks


