oops le code!!
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Les defines
#define EXPORT_FILE "./test.txt"
// Les types SQL
SQLHENV henv;
SQLHDBC hdbc;
SQLHSTMT hstmt;
using namespace std;
int main()
{
// Déclaration des variables SQL
SQLRETURN retcode;
SQLINTEGER cbville, cbnom, cbprenom;
SQLCHAR szville[81],sznom[81],szprenom[81];
// Déclaration des variables Standart
char requete[1024+1]="select ville,nom,prenom from liste Where ville='paris' ";
char Serveur[81]="Provider=MSDASQL.1;Persist Security Info=False;Data Source=MS Access Database";
char Login[81]="root";
char Pwd[81]="";
FILE *fp;
// Connexion à la base de données
retcode=SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
retcode=SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3,0);
if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{retcode=SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
printf(" Connexion etablie.... youpiii !!!!!");
}
else
printf("Erreur sur l'instruction SQLAllocHandle !\\n");
// Vérification du Lien ODBC, Login Et Pwd
if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
retcode=SQLConnect(hdbc, (SQLCHAR*)Serveur, SQL_NTS, (SQLCHAR*)Login, SQL_NTS, (SQLCHAR*)Pwd, SQL_NTS);
else
printf("Erreur sur l'instruction SQLSetEnvAttr !\\n");
if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
retcode=SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
else
printf("Erreur sur l'instruction SQLConnect !\\n");
// Execution de la requete
if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
retcode=SQLExecDirect(hstmt, (SQLCHAR*)requete, SQL_NTS);
else
printf("Erreur sur l'instruction SQLAllocHandle !\\n");
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
// Récupération des informations contenu dans les champs des tables
SQLBindCol(hstmt, 1, SQL_C_CHAR, szville,80, &cbville);
SQLBindCol(hstmt, 2, SQL_C_CHAR, sznom, 80, &cbnom);
SQLBindCol(hstmt, 3, SQL_C_CHAR, szprenom, 80, &cbprenom);
}
else
printf("Erreur sur l'instruction SQLExecDirect !\\n");
// Déconnexion
SQLFreeStmt(hstmt, SQL_DROP);
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
system("pause");
return 0;
}
|