954,566 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

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
#include
#include
#include
#include
#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<\t%25s\r\n", Name, Desc);

}
pos++;
};
}
else {
printf("Connection failed.");
}
link.Disconnect();
//getch();
char asd;
cin>> asd;
return 0;
}

Chester1
Newbie Poster
11 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

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....

clartsonly
Newbie Poster
15 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

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));
clartsonly
Newbie Poster
15 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: