003
07.09.2003, 21:35 Uhr
Uwe
C/C++ Master (Administrator)
|
Hallo Flo, ich denke Er meint das z.B. so:
C++: |
#include "stdio.h" #include "stdlib.h" #include "windows.h" #include <sql.h> #include <sqlext.h>
#pragma comment (lib,"odbc32.lib") char * connection_string = "DBQ=db1.mdb;DRIVER={Microsoft Access Driver (*.mdb)};"; char * sql_statement = "select * from Namen where Name = 'Meyer'";
int main(int argc, char* argv[]) { SQLHANDLE env,stat,conn; SQLRETURN retval;
char * full_connection_string = (char *)malloc(1024); unsigned char * sz_colhere = (unsigned char *)GlobalLock(GlobalAlloc(GMEM_ZEROINIT,0xFF)); SQLINTEGER sz_colhere_size;
SQLSMALLINT full_connection_string_size;
retval =SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&env); if((retval != SQL_SUCCESS) && (retval != SQL_SUCCESS_WITH_INFO) ) return 1;
retval =SQLSetEnvAttr(env,SQL_ATTR_ODBC_VERSION,(void *)SQL_OV_ODBC3,NULL); if((retval != SQL_SUCCESS) && (retval != SQL_SUCCESS_WITH_INFO)) return 2;
retval = SQLAllocHandle(SQL_HANDLE_DBC,env,&conn); if((retval != SQL_SUCCESS) && (retval != SQL_SUCCESS_WITH_INFO) ) return 3; retval = SQLDriverConnect(conn, NULL, (unsigned char*)connection_string, strlen(connection_string), (unsigned char *)full_connection_string, 1024, &full_connection_string_size, SQL_DRIVER_COMPLETE );
if((retval != SQL_SUCCESS) && (retval != SQL_SUCCESS_WITH_INFO) ) return 4;
retval = SQLAllocHandle(SQL_HANDLE_STMT,conn,&stat); if((retval != SQL_SUCCESS) && (retval != SQL_SUCCESS_WITH_INFO) ) return 5;
printf("Connection String %s:\n\n",full_connection_string);
retval=SQLExecDirect(stat, (unsigned char *) sql_statement, strlen(sql_statement) );
if((retval != SQL_SUCCESS) && (retval != SQL_SUCCESS_WITH_INFO) ) return 6;
retval = SQLBindCol(stat, 1, SQL_C_CHAR, sz_colhere, 0xFF, &sz_colhere_size );
if((retval != SQL_SUCCESS) && (retval != SQL_SUCCESS_WITH_INFO) ) return 7;
while(SQLFetch(stat) != SQL_NO_DATA) { printf("value: %s\n",sz_colhere); }
SQLDisconnect(conn); SQLFreeHandle(SQL_HANDLE_ENV,env); SQLFreeHandle(SQL_HANDLE_DBC,conn); getchar(); return 0; }
|
-- "Es ist schwierig, ein Programm wirklich idiotensicher zu machen, weil Idioten so genial sind."
Bis dann... Uwe |