| | |
Need to make program access a data base primary key number entered by user
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2004
Posts: 11
Reputation:
Solved Threads: 0
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;
}
#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;
}
![]() |
Similar Threads
- adding from 0 to a number that will be entered by the user . (C)
- 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)
- Vb.net source code to access data from Access Database (Visual Basic 4 / 5 / 6)
- My solution to 2 beginner questions (C++)
- Program Problem with a select statement to access Data base (C)
- Newbie wants to access a database (C++)
Other Threads in the C Forum
- Previous Thread: Problem with working with math in C
- Next Thread: How To Use C Program To Create Lan Messaging
| Thread Tools | Search this Thread |
#include * append array arrays asterisks bash binarysearch calculate changingto char character cm copyimagefile creafecopyofanytypeoffileinc createprocess() database dynamic execv feet fgets file floatingpointvalidation fork forloop framework function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide include incrementoperators input intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix meter microsoft mqqueue number oddnumber odf opensource openwebfoundation overwrite owf pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprogramming standard strchr string systemcall testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi





