Program Problem with a select statement to access Data base

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

Program Problem with a select statement to access Data base

 
0
  #1
Sep 29th, 2004
Need HELP! This Program that accesses a data base will not print out information from Data Base.I think the Problem is in the SELECT statement.The Primary Key is ID1, I want to Access Primary Key 2, Field Father but when I run it, it will only print out Quote: " 0: Colums 0"end Quote. The Select Statement is SQL, NEED HELP!

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 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 WHERE ID1=2,Father* FROM \"DD 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;
}
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 1
Reputation: sergio is an unknown quantity at this point 
Solved Threads: 0
sergio sergio is offline Offline
Newbie Poster

Re: Program Problem with a select statement to access Data base

 
0
  #2
Sep 30th, 2004
hi,
the problem is the string strQuery.
The correct form of a SELECTION QUERY is
select [* or any field of the table] from [name_of_table] where filed1 = 'any number or any string';

for example if I want to view all the name and the age of the table people that have age>18:
SELECT name,age FROM people where age>18;

In access the name of the table strated with [ and ended with ] so the query become:
SELECT name,age FROM [people] where age>18;

I think it help you. bye
Sergio
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