Chester1 0 Newbie Poster

This code works to access the whole file, but need to access the primary key. Please help! Thanks! :mrgreen:

#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <tchar.h>
#include "ODBCWrapper.cpp"
//make sure you include the namespace
using namespace ODBC;

int main(void) {
  MDBConnection link;
  if(link.Connect("C:\\Documents and Settings\\Chester Mayle\\My Documents\\My Data Sources\\db1.mdb")) {
    ODBCStmt Stmt(link);
    SQLExecDirect(Stmt, (SQLTCHAR *) _T("USE Foo"), SQL_NTS);
    int pos = 1;
    TCHAR strQuery[256] = _T("SELECT * FROM \"ID Data Base\"");
    int nRet = Stmt.Query(strQuery);
    printf("%5d:\tColumns\t%d\r\n\r\n", Stmt.GetColumnCount(), 0);
    while(Stmt.Fetch()) {
      ODBCRecord rec(Stmt);
      printf("Row %5d\r\n", pos);
      INT i = 0;
      while(i < Stmt.GetColumnCount()) {
        TCHAR Desc[512] = _T("");
        SQLINTEGER cbDesc = 0;
        rec.GetData(i + 1, Desc, sizeof(Desc), & cbDesc);
        TCHAR Name[256] = _T("");
        rec.GetColumnName(i + 1, Name, sizeof(Name));
        i++;
        printf("\t%15s\t\\>\t%25s\r\n", Name, Desc);
      }
      pos++;
    };
  }
  else {
    printf("Connection failed.");
  }
  link.Disconnect();
  //getch();
  return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.