1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| #include "windows.h"
# include <stdio.h>
# include <sql.h>
# include <sqlext.h>
SQLHSTMT hstmt ;
SQLHENV henv ;
SQLHDBC hdbc ;
RETCODE retcode;
......
..............
........
.....................
void UpdSeqCpt (HWND hwnd, char *compte_courrant, int cp_numseq)
{
UINT nindex;
char cpt_courrant[24];
int cpt_numseq;
hstmt = SQL_NULL_HSTMT;
hdbc = SQL_NULL_HDBC;
henv = SQL_NULL_HENV;
strcpy(cpt_courrant, compte_courrant);
cpt_numseq = cp_numseq;
nindex=0;
retcode = SQLAllocEnv(&henv);
if (retcode == SQL_SUCCESS) {
retcode = SQLAllocConnect (henv, &hdbc);
if (retcode == SQL_SUCCESS) {
retcode = SQLConnect (hdbc, DataBaseUsed, SQL_NTS, "", SQL_NTS, "", SQL_NTS);
if (retcode == SQL_SUCCESS) {
retcode = SQLAllocStmt (hdbc, &hstmt);
if ((retcode == SQL_SUCCESS) || (retcode == SQL_SUCCESS_WITH_INFO))
{
retcode = SQLPrepare (hstmt, "UPDATE COMPTES SET CP_DERSEQ = ? WHERE (CP_CLE = ?)", SQL_NTS);
if ((retcode == SQL_SUCCESS) || (retcode == SQL_SUCCESS_WITH_INFO))
{
if ((SQLSetParam (hstmt,1,SQL_C_SHORT,SQL_SMALLINT,0,0,&cpt_numseq,NULL) == SQL_SUCCESS)
&& (SQLSetParam (hstmt,2,SQL_C_CHAR,SQL_CHAR,sizeof(cpt_courrant),0,cpt_courrant,NULL) == SQL_SUCCESS)) {
retcode = SQLExecute (hstmt);
if ((retcode == SQL_SUCCESS) || (retcode == SQL_SUCCESS_WITH_INFO))
nindex++;
else
geterror(hstmt);
}
else
geterror(hstmt);
}
else
geterror(hstmt);
SQLFreeStmt(hstmt, SQL_DROP);
}
else
geterror(hstmt);
SQLDisconnect(hdbc);
}
else
geterror(hstmt);
SQLFreeConnect(hdbc);
}
else
geterror(hstmt);
SQLFreeEnv(henv);
}
else
geterror(hstmt);
}
/*------------------------------------------------------------------*/
/* GESTION DES ERREURS ODBC */
/*------------------------------------------------------------------*/
static void geterror(SQLHSTMT hstmt)
{
char msg[256] ; /* pointer to message */
RETCODE rc; /* code erreur retour */
char szSqlState[6]; /* etat de retour */
long noError; /* no de message */
short cbmsg;
rc = SQLError(henv, hdbc, hstmt, szSqlState, &noError, msg, 256, &cbmsg);
MessageBox(NULL, msg, szAppli, MB_OK|MB_ICONEXCLAMATION);
} |
Partager