This works except that I am getting one error, however; it does still compile and returns info. The code then the error.
#include <windows.h>
#include <stdio.h>
#include <sqlext.h>
const char* DAM = "Direct ODBC";
SQLCHAR szDSN[256] =
"Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ=C:\\FILEBLOCK\\Fileblocker.accdb;";
main()
{
HENV hEnv;
HDBC hDbc;
SQLRETURN rc;
SQLSMALLINT iConnStrLength2Ptr;
SQLCHAR szConnStrOut[255];
SQLCHAR* query = "SELECT tblIP.[IPAddress], tblIP.[IPStatus], tblIP.[IPType] FROM tblIP ORDER BY tblIP.[IPAddress] ASC;";
SQLCHAR chval1[128], chval2[128], chval3[128], colName[128];
SQLINTEGER ret1, ret2, ret3;
SQLINTEGER rowCount = 0;
SQLSMALLINT fieldCount = 0, column = 0;
HSTMT hStmt;
rc = SQLAllocEnv(&hEnv);
rc = SQLAllocConnect(hEnv, &hDbc);
rc = SQLDriverConnect(hDbc, NULL, szDSN, _countof(szDSN),
szConnStrOut, 255, &iConnStrLength2Ptr, SQL_DRIVER_NOPROMPT);
if (SQL_SUCCEEDED(rc))
{
printf("%s: Successfully connected to database. Data source name: \n %s\n",
DAM, szConnStrOut);
printf("%s: SQL query:\n %s\n", DAM, query);
rc = SQLAllocStmt(hDbc,&hStmt);
rc = SQLPrepare(hStmt, query, SQL_NTS);
rc = SQLBindCol(hStmt, 1, SQL_C_CHAR, chval1, 128, &ret1);
rc = SQLBindCol(hStmt, 2, SQL_C_CHAR, chval2, 128, &ret2);
rc = SQLBindCol(hStmt, 3, SQL_C_CHAR, chval3, 128, &ret3);
rc = SQLExecute(hStmt);
if (SQL_SUCCEEDED(rc))
{
printf("%s: Retrieve schema info for the given result set:\n", DAM);
SQLNumResultCols(hStmt, &fieldCount);
if (fieldCount > 0)
{
for (column = 1; column <= fieldCount; column++)
{
SQLDescribeCol(hStmt, column,
colName, sizeof(colName), 0, 0, 0, 0, 0);
printf(" | %s", colName);
}
printf("\n");
}
else
{
printf("%s: Error: Number of fields in the result set is 0.\n", DAM);
}
printf("%s: Fetch the actual data:\n", DAM);
rc = SQLFetch(hStmt);
while (SQL_SUCCEEDED(rc))
{
printf(" | %s | %s\n", chval1, chval2, chval3);
rc = SQLFetch(hStmt);
rowCount++;
};
printf("%s: Total Row Count: %d\n", DAM, rowCount);
rc = SQLFreeStmt(hStmt, SQL_DROP);
}
}
else
{
printf("%s: Couldn't connect to %s.\n", DAM, szDSN);
}
SQLDisconnect(hDbc);
SQLFreeHandle(SQL_HANDLE_DBC, hDbc);
SQLFreeHandle(SQL_HANDLE_ENV, hEnv);
printf("%s: Cleanup. Done.\n", DAM);
}</string></odbcss.h></sqlext.h></sql.h></stdio.h></windows.h>
The Error, It's on the SELECT Statemnet.
1 IntelliSense: a value of type "const char *" cannot be used to initialize an entity of type "SQLCHAR *"