Need Help Accessing a Primary key MS Access in SQL to print out informatio.

Please support our MS Access and FileMaker Pro advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Sep 2004
Posts: 11
Reputation: Chester1 is an unknown quantity at this point 
Solved Threads: 0
Chester1 Chester1 is offline Offline
Newbie Poster

Need Help Accessing a Primary key MS Access in SQL to print out informatio.

 
0
  #1
Oct 4th, 2004
I am having problems making my code access the primary key, and to print information out to screen in a C++ program that I Am writing. Need some help PLEASE ! The Primary Key Name is ID1. HERE IS THE CODE

#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 std;
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 car1 FROM \ID Data Base\where ID1='2%'");
//t
//tl
//TCHAR strQuery[256] = _T("SELECT * FROM \ID Data Base\"");
//int nRet =
cout<<Stmt.Query(strQuery);
printf("%5d:\tColumns\t%d\r\n\r\n", Stmt.GetColumnCount(), 0);
string cg;
//SELECT [ID1] FROM [ID Data Base] where ID1='2%'";

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("");
TCHAR Name[256] = _T( "WHERE ID1=2%");
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();
char asd;
cin>> asd;
return 0;
}
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 15
Reputation: clartsonly is an unknown quantity at this point 
Solved Threads: 0
clartsonly clartsonly is offline Offline
Newbie Poster

Re: Need Help Accessing a Primary key MS Access in SQL to print out informatio.

 
0
  #2
Oct 4th, 2004
isn't the problem the fact that you have not selected ID1 in your SQL statment?

TCHAR strQuery[256] = _T("SELECT car1 FROM \ID Data Base\where ID1='2%'");
try select ID1,car1 from blah blah....
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 15
Reputation: clartsonly is an unknown quantity at this point 
Solved Threads: 0
clartsonly clartsonly is offline Offline
Newbie Poster

Re: Need Help Accessing a Primary key MS Access in SQL to print out informatio.

 
0
  #3
Oct 4th, 2004
also I think the first column is 0 not 1
in your loop you reference i + 1 which will start with 1 not 0.

rec.GetData(i + 1, Desc, sizeof(Desc), & cbDesc);
//TCHAR Name[256] = _T("");
TCHAR Name[256] = _T( "WHERE ID1=2%");
rec.GetColumnName(i + 1, Name, sizeof(Name));
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC