| | |
Program Problem with a select statement to access Data base
![]() |
•
•
Join Date: Sep 2004
Posts: 11
Reputation:
Solved Threads: 0
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;
}
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;
}
•
•
Join Date: Sep 2004
Posts: 1
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- how to connect with data base add data (Visual Basic 4 / 5 / 6)
- Access Data Base in VC++ 6 (C++)
- Please help me with inserting to access data base (VB.NET)
- how to view the data accessed using mysql select statement (Visual Basic 4 / 5 / 6)
- MS Access data retrieval problem (Visual Basic 4 / 5 / 6)
- Vb.net source code to access data from Access Database (Visual Basic 4 / 5 / 6)
- Need to make program access a data base primary key number entered by user (C)
Other Threads in the C Forum
- Previous Thread: hi need help
- Next Thread: i need sm1 to help me with
| Thread Tools | Search this Thread |
* adobe ansi api array arrays binarysearch calculate centimeter char character cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking highest homework i/o inches incrementoperators intmain() iso km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. lowest match matrix microsoft mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pattern pdf performance posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h windowsapi





