IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MFC Discussion :

requete avec OBCD et visual c++


Sujet :

MFC

  1. #1
    Membre averti

    Homme Profil pro
    Inscrit en
    Mars 2002
    Messages
    0
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 0
    Points : 314
    Points
    314
    Par défaut requete avec OBCD et visual c++
    je ne trouve pas comment on fait des requete sous visual c++ avec OBCD
    j'utilise une base de données access 2000
    elle comprend une table avec quelques champs
    nom
    prenom
    adresse

    je voudrais fair eune fonction qui recherche dans ma base les enregistrement avec un nom donné dans un edit par exemple
    en gros comment on fait pour faire une requete
    dois je utilisé le SQL ?
    merci d'avance pour votre réponse(c pour mon projet bts de fin d'année

  2. #2
    Membre averti

    Homme Profil pro
    Inscrit en
    Mars 2002
    Messages
    0
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 0
    Points : 314
    Points
    314
    Par défaut ODBC
    Ce n'est pas simple ....
    Ce qu'il faut faire :
    1) Ouvrir la data base et regarder les tables MDB de la base : m_strDatabase = m_database.GetName();
    et faire éventuellement un choix sur une table
    2) créer un environnement : HENV
    3) Connection à ODBC /MDB : créer un HDBC
    4) Lancer SqlExecutedirect avec SqlFechScroll pour lister les éléments dela table.

    Ci joint un exemple de ENDUSER4GL , nouveau projet Vc++ "OPEN SOURCE".
    Vous trouverez plein d'exemples de programmes C++ (sql, queries, sort...) de EndUser4gl
    Notre projet Shareware : http:\\www.enduser4gl.com


    Bon courage
    Ph bergougnoux
    bergou@club-internet.fr
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
     
    //  ////////////////////////////////////////////////
    //  INITIALIZE GRID 4 : TABLE ACCES                 //
    ////////////////////////////////////////////////////
    SQLHDBC   EU_Create_HdbcACCES(LPSTR pstrFileName )  
    {  	CDaoDatabase m_database;
    	CString m_strDatabase;
    	CString m_strQuery;
     	CDaoTableDefInfo tdi;
    	int i,  NumDial,NumWin,y,   Result,nRows  ;
          char *szBuffer  ;
     	  SQLHDBC   hdbc ;                   //hdbc
         SQLRETURN nResult;                //result code
         SQLHSTMT  hstmt  ; 
     	HENV    henv;
    	RETCODE retcode;
    	BOOL IiSheet=FALSE;
      	CHAR    szDSNName[SQL_MAX_DSN_LENGTH + 1];
     
     	CHAR    szDSNNameDrivers[SQL_MAX_DSN_LENGTH + 1];
    	CHAR    szLegalDSNName[SQL_MAX_DSN_LENGTH + 1];
      	CHAR    szFileDSNName[1024];
     	char    *pvaleur;
       	UWORD	rgbValue;  		
     	 HCURSOR  hOldCursor;
     
    	  	    y=	SearchDialAndWin( hWndTBtnQuery4 ,&NumDial,&NumWin,2);
    			if(!y) { TRACEEU("Error Creation Window Query Load Table xls/mdb "); return 0;}
     
    	 	   for&#40;i=0;i < 40;i++&#41;//init GRID
    		   &#123;
    			   *&#40;int *&#41;Dialog&#91;NumDial&#93;.TabCoordWinGrid&#91;NumWin&#93;.InfoTable&#91;i&#93;&#91;1&#93; =0;
     
          	   	 AllocAddItemGridSql&#40;2,i,NumDial,NumWin, "\0"&#41;;
         	  	 AllocAddItemGridSql&#40;3,i,NumDial,NumWin, "mdb"&#41;;
    	   &#125;
     
    	 nRows=0;
    	 try &#123;
          // non exclusif, lecture seule
          m_database.Open&#40;pstrFileName, FALSE, TRUE&#41;;
        &#125;
        catch &#40;CDaoException* e&#41; &#123;
          &#58;&#58;DaoErrorMsg&#40;e&#41;;
              e->Delete&#40;&#41;;	 AfxDaoTerm&#40;&#41;; // hyper important 
          return 0;
        &#125;
     
    	 m_strDatabase = m_database.GetName&#40;&#41;;
    //     TRACEEU&#40;"Nom BDD = %s, \n",
     //        &#40;const char*&#41; m_strDatabase &#41;;
       	int nTables = m_database.GetTableDefCount&#40;&#41;;
         for &#40;int n = 0; n < nTables; n++&#41; &#123;
            m_database.GetTableDefInfo&#40;n, tdi&#41;;
             if &#40;tdi.m_strName.Left&#40;4&#41; != "MSys"&#41; &#123;
      		 	 	szBuffer = strdup&#40; tdi.m_strName&#41;;
    	 		   AllocAddItemGridSql&#40;2,nRows,NumDial,NumWin,&#40;char *&#41;  szBuffer&#41;;
    	 		    AllocAddItemGridSql&#40;3,nRows,NumDial,NumWin, &#40;char *&#41;"MDB"&#41;;
                   nRows++;
      	//  TRACEEU&#40;"TABLE GRID4...%s ",&#40;const char*&#41; szBuffer&#41;;
    	&#125;
    	 &#125; 
     
    		m_database.Close&#40;&#41;;  // route ECHAP
    	 	 AfxDaoTerm&#40;&#41;; // hyper important 
     
    // Attributes & Operations
      InvalidateRect&#40;hWndTBtnQuery4,0,0&#41;;
     ShowWindow&#40;HwndTQueryChild4,SW_RESTORE&#41;;
     SetForegroundWindow&#40;&#40;HWND&#41;HwndTQueryChild4&#41;;
          hOldCursor = SetCursor&#40;LoadCursor&#40;&#40;HINSTANCE&#41;NULL, IDC_WAIT&#41;&#41;;
     	 SetCursor&#40;&#40;LoadCursor&#40;&#40;HINSTANCE&#41;NULL, IDC_WAIT&#41;&#41;&#41;;
    	 ShowCursor&#40;TRUE&#41;;
     	    strcpy&#40;SQLInfoDriver&#91;5&#93;.EnvDatabaseSql,pstrFileName&#41;;
    	    strcpy&#40;SQLInfoDriver&#91;5&#93;.VerSql,"MS Access Driver"&#41;;
    	    strcpy&#40;SQLInfoDriver&#91;5&#93;.VerDriver ,"25"&#41;;
    		Format_Drivers_MDB&#40;&#41;;
                    SQLAllocHandle&#40;SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv&#41;;
    		&#40;void&#41; SQLSetEnvAttr&#40;henv, SQL_ATTR_ODBC_VERSION,
    					&#40;SQLPOINTER&#41; SQL_OV_ODBC3, SQL_IS_INTEGER&#41;;
     			retcode = 	SQLDrivers&#40;henv,SQL_FETCH_FIRST,&#40;unsigned char *&#41; szDSNNameDrivers,
    			sizeof&#40;szDSNNameDrivers&#41;, NULL, NULL, 0, NULL&#41;;
    // recherche du driver 
      		while&#40;SQL_SUCCEEDED&#40;retcode&#41;&#41;
    		&#123;	
    			if&#40;pvaleur = strstr&#40; szDSNNameDrivers,"Access Driver"&#41;&#41; 
    			&#123;
     
     				G_IncrDataSource++; 
    				memcpy&#40;szFileDSNName,"\0",MAXBUFLEN+1&#41;;  
    				 sprintf&#40;szLegalDSNName,"%05d",G_IncrDataSource&#41;;
    				strcpy&#40;szDSNName,"EndUser4gl"&#41;;strcat&#40;szDSNName,szLegalDSNName&#41;;	
    				strcat&#40;szFileDSNName,"DSN="&#41;;
    				strcat&#40;szFileDSNName,szDSNName&#41;;strcat&#40;szFileDSNName,";"&#41;;
    				strcat&#40;szFileDSNName,G_szFileDSNName&#41;; 
    				y= strlen&#40;szFileDSNName&#41;;
    		    for&#40;i = 0;i  <  y + 1 ;i++&#41; &#123;
    		    if&#40;!strncmp&#40;&#40;char *&#41; szFileDSNName+i,&#40;char *&#41;";",1&#41;&#41; 
    	   	  szFileDSNName&#91;i&#93; ='\0' ;
    		   &#125;
     
       strcat&#40;szDSNName,"\0"&#41;; 
            	SQLRemoveDSNFromIni&#40;szDSNName&#41;;
         	SQLConfigDataSource&#40;NULL,ODBC_REMOVE_DSN, szDSNNameDrivers,szFileDSNName&#41;;
     
        if&#40;! SQLWriteDSNToIni&#40;szDSNName, szDSNNameDrivers&#41;&#41;
    	&#123;	 TRACEEU&#40;"1 Erreur SQLWriteDSNToIni %s", szDSNNameDrivers&#41;; 
    		SQLFreeHandle&#40;SQL_HANDLE_ENV, henv&#41;;
     
    	return 0;
    	&#125;
     
     	   	if&#40;!SQLConfigDataSource&#40;NULL,ODBC_ADD_DSN, szDSNNameDrivers,szFileDSNName&#41;&#41;
    		&#123;  	  TRACEEU&#40;"4 Erreur SQLConfigDataSource  %s", szDSNNameDrivers&#41;;   
    			  TRACEEU&#40;"4 Erreur SQLConfigDataSource  %s", szFileDSNName&#41;;   
    				SQLFreeHandle&#40;SQL_HANDLE_ENV, henv&#41;;
    				SQLRemoveDSNFromIni&#40;szDSNName&#41;;
     		return 0;
    		&#125;
     
     
     	if &#40;&#40;nResult = SQLAllocHandle&#40;SQL_HANDLE_DBC,henv, &#40;SQLHDBC FAR *&#41;&hdbc&#41;&#41; != SQL_SUCCESS&#41; &#123;
    			DisplayError&#40;nResult, 0, SQL_HANDLE_ENV, henv&#41;;
    		   	SQLFreeHandle&#40;SQL_HANDLE_ENV, henv&#41;;
    			SQLRemoveDSNFromIni&#40;szDSNName&#41;;
    		 	SQLConfigDataSource&#40;NULL,ODBC_REMOVE_DSN, szDSNNameDrivers,szFileDSNName&#41;;
    			SQLDisconnect&#40;hdbc&#41;;
    			SQLFreeHandle&#40;SQL_HANDLE_DBC, hdbc&#41;;
    			return 0;
        &#125;
      		//test SQL_AUTOCOMMIT		
     	 		nResult = SQLSetConnectAttr&#40;hdbc,SQL_AUTOCOMMIT,&#40;void *&#41;SQL_AUTOCOMMIT_ON,SQL_IS_INTEGER&#41;;
          	 if&#40;&#40;nResult != SQL_SUCCESS &#41; &#41; 
    		 &#123;TRACEEU&#40;"PB03%d",nResult&#41;;
            DisplayError&#40;nResult, 0, SQL_HANDLE_STMT, hdbc&#41;;
            return 0;
    		 &#125;
     
      	 	nResult = SQLSetConnectAttr&#40;hdbc,SQL_ACCESS_MODE,&#40;void *&#41;SQL_MODE_READ_ONLY,SQL_IS_INTEGER&#41;;
       	 if&#40;&#40;nResult != SQL_SUCCESS &#41;  &#41; 
     	&#123;TRACEEU&#40;"PB02%d",nResult&#41;;
         DisplayError&#40;nResult, 0, SQL_HANDLE_STMT, hdbc&#41;;
          return 0;
    	 &#125;
     
     
     		//test SQL_LOGIN_TIMEOUT
    		//the choice of 15 seconds for timeout is arbitrary
    		rgbValue = 15;
       	nResult =  SQLSetConnectAttr&#40;hdbc,SQL_LOGIN_TIMEOUT,&#40;void *&#41;&rgbValue ,SQL_IS_INTEGER&#41;;
        	 if&#40;&#40;nResult != SQL_SUCCESS &#41; &#41; 
    		 &#123;TRACEEU&#40;"PB04%d",nResult&#41;;
          DisplayError&#40;nResult, 0, SQL_HANDLE_STMT, hdbc&#41;;
           return 0;
    		 &#125;
    // CONNECTION  ODBC/MDB BY TRANSPARENCY ******************************
      nResult = SQLConnect&#40;hdbc,&#40;unsigned char *&#41;szDSNName,SQL_NTS,&#40;unsigned char *&#41;"",\
    	 SQL_NTS,&#40;unsigned char *&#41;"",SQL_NTS&#41;;
        	  	if&#40;nResult == SQL_SUCCESS || nResult == SQL_SUCCESS_WITH_INFO&#41;
    		&#123;   	// try to get a list of columns for the table
     		    nResult = SQLAllocHandle&#40;SQL_HANDLE_STMT,hdbc, &#40;SQLHSTMT FAR *&#41;&hstmt&#41;;
    				 Result=0;
     
    			 	if&#40;nResult == SQL_SUCCESS || nResult == SQL_SUCCESS_WITH_INFO&#41;
    				&#123; 	
    						   G_hdbc = hdbc; // tres important
                               G_hstmt = hstmt; // tres important
     						strcpy&#40;  G_szDSNName,szDSNName&#41;;
     						strcpy&#40;  G_szDSNNameDrivers,szDSNNameDrivers&#41; ;
    						strcpy&#40;  G_szFileDSNNameODBC,szFileDSNName&#41; ;
    						G_henv = henv;
    						ExecuteSQLDialog&#40; hdbc,    hstmt,pstrFileName&#41; ;
                                   return hdbc;
    				&#125;//if&#40;nResult == SQL_SUCCESS
    				else
    				&#123;
      	 	 			DisplayError&#40;nResult, 0, SQL_HANDLE_STMT, hdbc&#41;;
    		 		 	SQLFreeHandle&#40;SQL_HANDLE_ENV, henv&#41;;
    		 			SQLRemoveDSNFromIni&#40;szDSNName&#41;;
     	 	 			SQLConfigDataSource&#40;NULL,ODBC_REMOVE_DSN, szDSNNameDrivers,szFileDSNName&#41;;
    		 			SQLDisconnect&#40;hdbc&#41;;
    		 			SQLFreeHandle&#40;SQL_HANDLE_DBC, hdbc&#41;;
    						MessageBox&#40;0, INITERROR, EXECERROR, MB_OK|MB_ICONHAND&#41;;
    	 	 		return 0;
    				&#125;
     
    		&#125;// nResult = SQLConnect
    				else
    				&#123;
      	 	 			DisplayError&#40;nResult, 0, SQL_HANDLE_STMT, hdbc&#41;;
    		 		 	SQLFreeHandle&#40;SQL_HANDLE_ENV, henv&#41;;
    		 			SQLRemoveDSNFromIni&#40;szDSNName&#41;;
     	 	 			SQLConfigDataSource&#40;NULL,ODBC_REMOVE_DSN, szDSNNameDrivers,szFileDSNName&#41;;
    		 			SQLDisconnect&#40;hdbc&#41;;
    		 			SQLFreeHandle&#40;SQL_HANDLE_DBC, hdbc&#41;;
     
    				 	MessageBox&#40;0, INITERROR, EXECERROR, MB_OK|MB_ICONHAND&#41;;
    				&#125;
     
     
     
    		break;
    		&#125; //if Excel driver
    				retcode = 	SQLDrivers&#40;henv,SQL_FETCH_NEXT,&#40;unsigned char *&#41; szDSNNameDrivers,
    			sizeof&#40;szDSNNameDrivers&#41;, NULL, NULL, 0, NULL&#41;;
     
     &#125;// while
    	  return 0 ;
     
     
     
    &#125;
     
     
    int FAR PASCAL ExecuteSQLDialog&#40;SQLHDBC   hdbc, SQLHSTMT  hstmt,char *szBuffer&#41; 
    &#123;
     
        SWORD     nCols = 0;                  // # of result columns
       SWORD     nCount;                     // index
       SWORD     swColType;                  // column data type
       SWORD     swColScale;                 // column scale
       SWORD     swColNull;                  // nullable column ?
       SWORD     swColLength = MAXDATALEN;   // column data length
        UDWORD    udwColDef;                  // precision on the column
       SQLRETURN nReturn;                    // return code
       HCURSOR   hOldCursor;                 // default cursor handle
       int       nRows,i=0,y,NumDial,NumWin;                      // # of result rows
     	MSG msg;
     	RECT rc;
      //	strcpy&#40;szBuffer," SELECT  * FROM   clients    WHERE clients.CODE_CLIEN like '*A*'  "&#41;;
     
      // change cursor shape to hour glass
     //TRACEEU&#40;"%d Wait..........Please %s",strlen&#40;szBuffer&#41;,szBuffer&#41;;
       hOldCursor = SetCursor&#40;LoadCursor&#40;&#40;HINSTANCE&#41;NULL, IDC_WAIT&#41;&#41;;
     	 SetCursor&#40;&#40;LoadCursor&#40;&#40;HINSTANCE&#41;NULL, IDC_WAIT&#41;&#41;&#41;;
         ShowCursor&#40;TRUE&#41;;
     	nReturn =SQLPrepare&#40;hstmt,&#40;unsigned char *&#41;szBuffer,strlen&#40;szBuffer&#41;&#41;;
    	GlobalDoubleValResult = &#40;double&#41;nReturn;
     
      		if&#40; nReturn != SQL_SUCCESS &#41; 
    		&#123; 
       			DisplayError&#40;nReturn, hWndFrameSQL, SQL_HANDLE_STMT, hstmt&#41;;
    			  	 while &#40;PeekMessage&#40;&msg, 0, 0, 0, PM_REMOVE&#41;&#41;// hyper important &#58;nettoyer
                     DispatchMessage &#40;&msg&#41; ;
     
    			SQLCloseCursor&#40;hstmt&#41;;
     			SQLFreeStmt&#40;hstmt, SQL_CLOSE&#41;;
    				GlobalDoubleValResult = -1;// no select
    		     return EUError;
    		&#125;
     
     
        nReturn = SQLExecDirect&#40;hstmt, &#40;unsigned char *&#41;szBuffer,strlen&#40;szBuffer&#41; &#41;;
    	GlobalDoubleValResult = &#40;double&#41;nReturn;
     	if&#40;nReturn != SQL_SUCCESS &#41; 
        &#123;
           DisplayError&#40;nReturn, hWndFrameSQL, SQL_HANDLE_STMT, hstmt&#41;;
       // if the return value was just information, carry on
             // Close the open result set.
    	     	 while &#40;PeekMessage&#40;&msg, 0, 0, 0, PM_REMOVE&#41;&#41;// hyper important &#58;nettoyer
                     DispatchMessage &#40;&msg&#41; ;
     
       			SetCursor&#40;hOldCursor&#41;;
     			DestroyWindow&#40;hWndFrameSQL&#41; ; 
    			SQLCloseCursor&#40;hstmt&#41;;
    			SQLFreeStmt&#40;hstmt, SQL_CLOSE&#41;;
       // restore the cursor to default value
    				SetCursor&#40;hOldCursor&#41;;
    				GlobalDoubleValResult =  1;
    		        return EUError; ;
        &#125;
        // call SQLNumResultCols to calculate the number of columns in
       // the result set, if more than the MAX_COL &#40;the array boundary&#41;
       // limit the number to MAX_COL and display truncation warning.
       // if it is 0, the statement probably was a non-SELECT simply return
       nReturn = SQLNumResultCols&#40;hstmt, &nCols&#41;;
     //printfEU&#40;"  nCols %d",nCols&#41;;STOP&#40;&#41;;STOP&#40;&#41;;STOP&#40;&#41;;
         if &#40;&#40;nCols == 0&#41;  &#41;
    	 &#123;  // if "INTO" in szBuffer
    		   	 while &#40;PeekMessage&#40;&msg, 0, 0, 0, PM_REMOVE&#41;&#41;// hyper important &#58;nettoyer
                     DispatchMessage &#40;&msg&#41; ;
     
    		 SQLCloseCursor&#40;hstmt&#41;;
    			 SetCursor&#40;hOldCursor&#41;;
     			//	DestroyWindow&#40;hWndFrameSQL&#41; ; 
    			  // restore the cursor to default value
    				SetCursor&#40;hOldCursor&#41;;
    				if&#40;&#40;strstr&#40;szBuffer,"into"&#41;&#41; || &#40;strstr&#40;szBuffer,"INTO"&#41;&#41;&#41;
    				&#123;	//printfEU&#40;"Find INTO............"&#41;;
    					return  GlobalDoubleValResult=0;//normal
    				&#125;
    			 	else return  GlobalDoubleValResult = 1;// not find
     
        &#125;
     
     //	 TRACEEU&#40;"1 Cols.......... &#58;%d",nCols&#41;;
      y=	SearchDialAndWin&#40; hWndBtnSQL ,&NumDial,&NumWin,2&#41;;
    if&#40;!y&#41; &#123; TRACEEU&#40;"Error Creation Window Sql "&#41;; return EUError;&#125;
     	   AllocGridSql&#40;2,nCols,64,26,NumDial,NumWin&#41;;
      GetWindowRect&#40;hWndFrameSQL,&rc&#41;;
    	 y =&#40;&#40;nCols + 1&#41; * 160&#41; +70 ;
    	 if&#40; y < rc.right&#41;&#123;
    		  SetWindowPos&#40;hWndFrameSQL, NULL,\
    		  rc.left, rc.top, y, rc.bottom,  
            SWP_NOZORDER | 	SWP_DRAWFRAME	 &#41;; 
    	 	// Ascenseur horizontal &#58; en bas, nouvelles dimensions
    		  GetClientRect&#40;hWndFrameSQL,&rc&#41;;
      		MoveWindow&#40;Dialog&#91;NumDial&#93;.TabCoordWinGrid&#91;NumWin&#93;.hwndTableur&#91;1&#93;,0,rc.bottom-96,\
    			rc.right-86,16,0&#41;;
    		// Ascenseur vertical &#58; à droite, nouvelles dimensions
     		MoveWindow&#40;Dialog&#91;NumDial&#93;.TabCoordWinGrid&#91;NumWin&#93;.hwndTableur&#91;2&#93;,rc.right-86,\
    		Dialog&#91;NumDial&#93;.TabCoordWinGrid&#91;NumWin&#93;.HeightGrid,16,rc.bottom-96-Dialog&#91;NumDial&#93;.TabCoordWinGrid&#91;NumWin&#93;.HeightGrid,0&#41;;
     
    	 &#125;
     
       // call SQLBindCol to bind column data array and column data length
       // array to the result set
      SQLSetStmtAttr&#40;hstmt, SQL_ATTR_ROW_BIND_TYPE, SQL_BIND_BY_COLUMN, 0&#41;;
     
        for&#40;nCount=1, szBuffer&#91;0&#93;='\0'; nCount <= nCols; nCount++&#41; &#123;
     
         SQLDescribeCol&#40;hstmt, nCount,&#40;unsigned char *&#41; szBuffer, MAXDATALEN, &swColLength, &swColType, &udwColDef,
                          &swColScale, &swColNull&#41;;
     	  SQLBindCol&#40;hstmt, &#40;UWORD&#41;&#40;nCount&#41;, SQL_C_CHAR,&#40;void *&#41;szBuffer, MAXDATALEN, &dwDataLen&#41;;
      	  AllocColumnGridSqlPUSHBUTTON&#40;NumDial,NumWin&#41;;
    			 	   AllocColumnGridSql&#40;nCount,NumDial,NumWin,szBuffer&#41;;
    	&#125;
          // call SQLFetch to fetch each row of the result set. Extract data
       // value and store it in the display buffer, separated by tabs.
       // continue until SQLFetch fails.
     //	  CenterWindow&#40;hWndFrameSQL&#41;;
     y=0;
     // SQLFECTHSCROLL ***************************************************************
           for&#40;nRows = 0; &#40;nReturn = SQLFetchScroll&#40;hstmt,SQL_FETCH_NEXT,0&#41;&#41;==SQL_SUCCESS \
    		  || nReturn==SQL_SUCCESS_WITH_INFO;&#41; &#123;
    		   if&#40;nRows >1 &#41;&#123; 
    		Dialog&#91;NumDial&#93;.TabCoordWinGrid&#91;NumWin&#93;.LigneAColler =nRows  ;
    		Dialog&#91;NumDial&#93;.TabCoordWinGrid&#91;NumWin&#93;.LigneClicDroit =nRows  ;
     		CopierLigne&#40;NumDial, NumWin&#41;;
      		 CollerLigne&#40;NumDial, NumWin&#41;;
    		   &#125;
    		   else
              AllocMallocItemGridSql&#40;nRows,NumDial,NumWin&#41;;
     		 for&#40;nCount=1; szBuffer&#91;0&#93;='\0',  nCount<= nCols+1 ; nCount++&#41; &#123;
     
     
    	 SQLGetData&#40;hstmt, &#40;UWORD&#41;&#40;nCount&#41;, SQL_C_CHAR,&#40;unsigned char *&#41; szBuffer,\
    		 MAXDATALEN, &dwDataLen &#41;;
     
       	 		 AllocAddItemGridSql&#40;nCount,nRows,NumDial,NumWin, &#40;char *&#41;szBuffer&#41;;
     			 y++;
     
    		 &#125; 
    		  if&#40;nRows<10&#41; //visual express
    	 &#123;       	 	Dialog&#91;NumDial&#93;.TabCoordWinGrid&#91;NumWin&#93;.NbLines =nRows +1;
    	  	Dialog&#91;NumDial&#93;.TabCoordWinGrid&#91;NumWin&#93;.StructureNbLignes=nRows +1;//tres important
     
     
    			  CenterWindow&#40;hWndFrameSQL&#41;;
                ShowWindow&#40;hWndFrameSQL, SW_SHOWNORMAL&#41; ;
     	        UpdateWindow&#40;hWndFrameSQL&#41;;
    	&#125;
        nRows++;
    	   &#125; 
     
    	     	 	Dialog&#91;NumDial&#93;.TabCoordWinGrid&#91;NumWin&#93;.NbLines =nRows ;
    	  	Dialog&#91;NumDial&#93;.TabCoordWinGrid&#91;NumWin&#93;.StructureNbLignes=nRows ;//tres important
     
        	 CenterWindow&#40;hWndFrameSQL&#41;;
      	     ShowWindow&#40;hWndFrameSQL, SW_SHOWNORMAL&#41; ;
      	  	    i= UpdateWindow&#40;hWndFrameSQL&#41;;
        SQLCloseCursor&#40;hstmt&#41;; //important laisser en commentaire voir Query.cpp
       SQLFreeStmt&#40;hstmt, SQL_UNBIND&#41;;
       	 while &#40;PeekMessage&#40;&msg, 0, 0, 0, PM_REMOVE&#41;&#41;
                     DispatchMessage &#40;&msg&#41; ;
     
     
         // restore the cursor to default value
       SetCursor&#40;hOldCursor&#41;;
       GlobalDoubleValResult = 0;
       return  	msg.wParam;
    &#125;

  3. #3
    Membre averti

    Homme Profil pro
    Inscrit en
    Mars 2002
    Messages
    0
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 0
    Points : 314
    Points
    314
    Par défaut
    ca ma l'air assez compliquer
    est ce qu'il y aurai une facon de faire des recherche dans ma table plus simplement car je n'utilise que une table dans ma base de données?

    merci d'avance

    si la dificulté était mortelle visual serai un cimetière !

  4. #4
    Expert confirmé
    Avatar de debug
    Profil pro
    Inscrit en
    Avril 2002
    Messages
    1 034
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 034
    Points : 4 093
    Points
    4 093
    Par défaut
    Voila un code qui peut d'aider enfin j'espère !!



    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    int main&#40;&#41;
    &#123;
    SQLRETURN	rc;
    SQLHENV		henv;
    SQLHDBC		hdbc1;
    SQLHSTMT	                hstmt1;
     
    char		CodeLivre&#91;7&#93;;
    long		CCodeLivre;
    char		Titre&#91;51&#93;;
    long		CTitre;
    char		NumSection&#91;5&#93;;
    long		CNumSection;
     
    int		Choix;
    char*		MonDSN=new char&#91;20&#93;;
     
    // allocation du handle d'environnement et définition de la version
    rc = SQLAllocHandle&#40;SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv&#41;;
    rc = SQLSetEnvAttr&#40;henv, SQL_ATTR_ODBC_VERSION, &#40;SQLPOINTER&#41;SQL_OV_ODBC3, 0&#41;;
     
    strcpy&#40;MonDSN,"Bibli Access"&#41;;
     
    // allocation du handle de connexion et connexion
    rc = SQLAllocHandle&#40;SQL_HANDLE_DBC, henv, &hdbc1&#41;;
    rc = SQLConnect&#40;hdbc1, &#40;unsigned char*&#41;MonDSN, SQL_NTS, &#40;unsigned char*&#41; "bibli", SQL_NTS, &#40;unsigned char*&#41;"bibli", SQL_NTS&#41;;
     
    // allocation du handle de statement
    rc = SQLAllocHandle&#40;SQL_HANDLE_STMT, hdbc1, &hstmt1&#41;;
     
    // Bind Parametre
    rc= SQLBindParameter&#40;hstmt1, 1, SQL_PARAM_INPUT, SQL_C_CHAR,SQL_CHAR, 4, 0, NumSection, 5, &CNumSection&#41;;
    CNumSection = SQL_NTS;
     
    // choix de la section
    printf&#40;"Choix de la section &#58;"&#41;;
    fflush&#40;stdin&#41;;
    gets&#40;NumSection&#41;;
     
    // envoi de la requête de comptage
    rc = SQLExecDirect&#40;hstmt1,&#40;unsigned char*&#41;"SELECT code_livre, titre FROM Livre WHERE code_section= ? ORDER BY Titre", SQL_NTS&#41;;
     
    // attache à une variable C
    rc = SQLBindCol&#40;hstmt1, 1, SQL_C_CHAR, CodeLivre, 7, &CCodeLivre&#41;;
    rc = SQLBindCol&#40;hstmt1, 2, SQL_C_CHAR, Titre, 51, &CTitre&#41;;
     
    // récupération du résultat
    rc = SQLFetch&#40;hstmt1&#41;;
     
    // affichage du résultat
    while&#40;rc ==0&#41;
    &#123;
    	printf&#40;"Livre &#58; %s , %s\n", CodeLivre, Titre&#41;;
    	rc=SQLFetch&#40;hstmt1&#41;;
    &#125;
    fflush&#40;stdin&#41;;
    getchar&#40;&#41;;
     
    // fermeture du curseur
    SQLCloseCursor&#40;hstmt1&#41;;
     
    // libération des handles et déconnexion
    SQLFreeHandle&#40;SQL_HANDLE_STMT, hstmt1&#41;;
    SQLDisconnect&#40;hdbc1&#41;;
    SQLFreeHandle&#40;SQL_HANDLE_DBC, hdbc1&#41;;
    SQLFreeHandle&#40;SQL_HANDLE_ENV, henv&#41;;
     
    return 0;
    &#125;
    Tu n'a qu'a remplacé :
    - la requete SQL par celle que tu veux.
    - le nom de ta variable paramètre.
    May the Troll, be with you
    (Que le troll soit avec toi)

  5. #5
    Futur Membre du Club
    Inscrit en
    Avril 2002
    Messages
    7
    Détails du profil
    Informations forums :
    Inscription : Avril 2002
    Messages : 7
    Points : 7
    Points
    7
    Par défaut
    Bien sur, car la facon qui est decrite plus haut est bien trop compliquée!!!!

    Tu déclare ta CDatabase tu fais un open dessus avec le nom de ta base,password,utilisateur et tu declare un CRecordset en lui passant l adresse de ta base et la requete SQL que tu veux.

    Voila, pour toi ca sera du genre
    CDatabase db;
    db.Open(_T("DSN =....,UID = ...., ....);
    tu declare ton recordset :
    CRecordset rs(&db);
    rs.Open("SELECT table.nom,table.adresse,table.prenom FROM table ORDER by table.nom");->regarde la methode CRecordset::Open pour les parametres car je crois qu il y en a d autres!

    et apres tu peux faire rs.MoveFirst() ou MoveNext() ou ....;

    pour modifier tu fais un rs.edit() et tu modifie ton recordset comme tu veux et apres tu fais rs.Update() ..

  6. #6
    Membre averti

    Homme Profil pro
    Inscrit en
    Mars 2002
    Messages
    0
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 0
    Points : 314
    Points
    314
    Par défaut azertyui
    Peut on déclarer le DSN directement dans l'appli sous Visual où faut il obligatoirement passer par le panneau de configuration Windows????

  7. #7
    Expert confirmé
    Avatar de debug
    Profil pro
    Inscrit en
    Avril 2002
    Messages
    1 034
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 034
    Points : 4 093
    Points
    4 093
    Par défaut
    Eh bien il y a deux choses différentes :
    - si tu veux utiliser un DSN, il doit obligatoirement existé dans le panneau de configuration WIndows -> outils d'administration -> Source de données ODBC. En fait un DSN est un raccourci.
    - si tu ne veux pas déclarer de DSN, tu utilise directement les attributs de la base c'est à dire : son nom, un login et un password pour te connecter.

    Voila...
    May the Troll, be with you
    (Que le troll soit avec toi)

  8. #8
    Futur Membre du Club
    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7
    Points : 8
    Points
    8
    Par défaut
    Bonjour à tous,

    Moi aussi je compte acceder à une base Access en c++. Selon les conseils de deftonesMichael, je tente de passer par une CDatabase.

    En lisant un peu la doc dessus, je fais bien #include <afxdb.h>

    Seulement, à peine j'essaye de déclarer une variable:
    ça refuse de compiler (erreur de link, plus précisement)
    Linking...
    nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
    nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex

    Je soupsonne que cela vienne du fait que je sois parti d'un projet Win32 Console Application - Hello world Application. Donc, sans support des MFC par defaut.

    Dois je repartir d'un projet application that supports MFC ??

    Merci de vos lumieres

    wAx

  9. #9
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    salut au cas ou
    il des liens interessants sur l'acces ODBC :
    exemple classe STL :
    http://www.codeguru.com/mfc_database/Cidsql.html
    une autre implementation par tom archer:
    http://www.codeguru.com/mfc_database/dynamic_odbc_class.shtml
    sinon regarder sur codeguru
    http://www.codeguru.com/mfc_database/index.shtml
    pleins de possibilites.

  10. #10
    Membre habitué Avatar de BertrandA
    Inscrit en
    Août 2003
    Messages
    170
    Détails du profil
    Informations forums :
    Inscription : Août 2003
    Messages : 170
    Points : 197
    Points
    197
    Par défaut
    si tu veux utiliser un DSN, il doit obligatoirement existé dans le panneau de configuration WIndows
    Il me semble qu'il existe un truc pour créer un DSN dynamiquement s'il n'existe pas dans le panneau de config, mais je n'arrive pas à remettre la main dessus.
    Les orteils servent à trouver les pieds de chaise et les montants de porte quand il fait noir.

  11. #11
    Membre averti
    Inscrit en
    Mars 2004
    Messages
    425
    Détails du profil
    Informations forums :
    Inscription : Mars 2004
    Messages : 425
    Points : 358
    Points
    358
    Par défaut
    BertrandA!!
    Est ce que tu as retrouvé ton truc pour créer la DNS dynamiquement?

    Merci
    OS:Win 2000 Pro, WIN XP
    SGBD: MS Sql Server, Oracle
    Environnement: VS.NET 2002, JBuilder
    Web: www.ndestudents.com

  12. #12
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2004
    Messages
    1
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2004
    Messages : 1
    Points : 1
    Points
    1
    Par défaut création DNS dynamique
    Bonjour,

    avec l'objet suivant:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    class C_DataBaseMsSql &#58; public CDataBase
    &#123;
    public&#58;
    	C_DataBaseMsSql&#40;&#41;;
    	~C_DataBaseMsSql&#40;&#41; &#123;&#125;
    	bool Init&#40;&#41;;
    	bool Open&#40;&#41;;
    	bool GetDriver&#40;&#41;;
    public&#58;
    	CString m_SDataBaseName;
    &#125;;
     
    et le source qui suit&#58;
     
    C_DataBaseMsSql&#58;&#58;C_DataBaseMsSql&#40;&#41;
    &#123;
    &#125;
     
    bool C_DataBaseMsSql&#58;&#58;Init&#40;&#41;
    &#123;
    	m_DwConnectOptions = CDatabase&#58;&#58;noOdbcDialog; 	m_SDsn = "MQIS";
    	m_SDataBaseName = "nom de la base";
    	m_SServerName = "nom du serveur";
     
    	m_SUserName="sa";
    	m_SPassword = "mot de passe SA";
     
    	GetDriver&#40;&#41;;
     
    	m_SConnectString.Format&#40;"DRIVER=&#123;%s&#125;;Server=%s;DSN=%s;DataBase=%s;Uid=%s;Pwd=%s",
    		m_SDriver, m_SServerName, m_SDsn, m_SDataBaseName, m_SUserName, m_SPassword&#41;;
     
    	return CDataBase&#58;&#58;Init&#40;&#41;;
    &#125;
     
    bool C_DataBaseMsSql&#58;&#58;Open&#40;&#41;
    &#123;
    	bool returnValue = &#40;m_CDatabase.OpenEx&#40;m_SConnectString, m_DwConnectOptions&#41;==0 ? false &#58; true&#41;;
    	if &#40;!returnValue&#41;
    		return false;
    	return CDataBase&#58;&#58;Open&#40;&#41;;
    &#125;
     
    bool C_DataBaseMsSql&#58;&#58;GetDriver&#40;&#41;
    &#123;
    	char szBuf&#91;2001&#93;;
    	WORD cbBufMax = 2000;
    	WORD cbBufOut;
    	char *pszBuf = szBuf;
     
    	// Get the names of the installed drivers &#40;"odbcinst.h" has to be included &#41;
    	if&#40;!SQLGetInstalledDrivers&#40;szBuf, cbBufMax, &cbBufOut&#41;&#41;
    		return false;
     
    	// Search for the driver...
    	do
    	&#123;
    		if&#40; strstr&#40; pszBuf, "SQL Server" &#41; != 0 &#41;
    		&#123;
    			// Found !
    			m_SDriver = CString&#40; pszBuf &#41;;
    			break;
    		&#125;
    		pszBuf = strchr&#40; pszBuf, '\0' &#41; + 1;
    	&#125;
    	while&#40; pszBuf&#91;1&#93; != '\0' &#41;;
     
    	return true;
    &#125;
    [Attention aux balises de code ,Farscape Merci]

  13. #13
    Membre éprouvé
    Avatar de Gabrielly
    Inscrit en
    Juin 2004
    Messages
    722
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 722
    Points : 1 128
    Points
    1 128
    Par défaut
    Bonjour ange1708

    Je crois avoir une réponse à ton problème.
    D'abord sache que c'est très simple. De bonnes explications résumé en dix pages seulement est suffisant pour vraiment démarrer avec ODBC.
    Je te conseil le livre Visual C++ 6.0 Chap 20 et 21. Je ne peux pas tout t'expliquer ici.
    Mais je vais être bref.

    1° Crée ta table sous Access comme tu l'as déjà fait.
    2° Tes champs sont : nom, prenom, adresse
    3° N'oublie pas une clé primaire comme le numéro d'ordre dans ta table
    ex: champs type
    N long
    Nom text
    Prenom text
    Adresse text
    4° Va dans panneaux de configuration de Window et trouve l'administrateur ODBC ( par ex sous Windows XP)
    5° Ajoute une source de donnée
    6° Sélectionne le pilote d'access
    7° Selectionne ta database ie le chemin
    8° Valide par OK toutes les boites de dialogues de l'administrateur ODBC
    9° Ouvre l' IDE de Visual C++
    10° Dans l'assistant choisit ton type de projet SDI ou MDI
    11° Sélectionne ta base de données mais attention
    12° Si elle est utilisé en lecture seule choisit l'option snapshot
    13° Si il y a des mise à jour choisit dynaset
    14° Commence par snapshot c'est plus simple
    15° Continue les autres options de configuration de ton projet
    16° Une fois ton projet ouvert tu as deux classes importantes du moins les classes dérivées de ceux-ci CRecordset et CRecordView
    17° CRecordset représente ta requête SQL
    18° CRecordView est un formulaire pour afficher les résultats de ta requête
    19° CRecordset comprend les données membres suivants:
    20° m_strFilter : c'est un CString qui contient la requête
    21° m_strSort : c'est un CString qui contient le nom du champ à trier
    22° il y en a beaucoup d'autres
    23° Dans OnInitialUpdate de la classe dérivée du CRecordView c'est là où tu commence tes requêtes selon tes besoin
    24° Ou dans une quelconque fonction de ton choix

    24° Voici un exemple de code qui peux t'inspirer.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
     void CMyRecordView&#58;&#58;OnInitialUpdate&#40;&#41;
    &#123;
    	BeginWaitCursor&#40;&#41;;
     
    	CPowerCircuitDoc* pDoc = GetDocument&#40;&#41;;
    	m_pSet = &pDoc->m_MyRecordSet;
    	m_pSet->m_strSort = "&#91;nom&#93;";  // pour trier suivant les noms
    	CRecordView&#58;&#58;OnInitialUpdate&#40;&#41;;   // on se connecte à la base indirectement par CRecordView&#58;&#58;OnInitialUpdate
     
    	if&#40;m_pSet->IsOpen&#40;&#41;&#41;   // on vérifie si la connection à réussie
    	&#123;
    		CString strTitle = m_pSet->m_pDatabase->GetDatabaseName&#40;&#41;;
    		CString strTable = m_pSet->GetTableName&#40;&#41;;
     
    		if &#40;!strTable.IsEmpty&#40;&#41;&#41;
    			strTitle += _T&#40;"&#58;"&#41; + strTable;
    		else
    			strTitle += _T&#40;"&#58; commande&#58; table multiples"&#41;;
     
    		GetDocument&#40;&#41;->SetTitle&#40;strTitle&#41;;  // on donne un titre suivant le nom de la table
    	&#125;
     
    	EndWaitCursor&#40;&#41;;
    &#125;

    Si l'utilisateur entre un nom que tu dois retoruver dans la base voici un peux code rapidement construit
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     void CMyRecordView&#58;&#58;SelectRecord&#40;CString name&#41;
    &#123; 
       m_pSet->m_NomParam = name;  // à déclarer m_NomParam dans le Recordset
       m_pSet->m_strFilter = "&#91;nom&#93; = ?";  // champ nom égale à ? ie m_NomParam 
       m_pSet->Requery&#40;&#41;;  // refait la requête
       UpdateData&#40;FALSE&#41;;
    &#125;
    Dans la CRecordView crée trois zones d'édition que tu associe aux variables CRecordset ie les champs de la table
    Verifie le dans DoDataExchange de CMyRecordView

    Dans le constructeur tu écrits
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     CMyRecordSet&#58;&#58;CMyRecordSet&#40;CDatabase* pdb&#41;
    	&#58; CRecordset&#40;pdb&#41;
    &#123;
    	//&#123;&#123;AFX_FIELD_INIT&#40;CMyRecordSet&#41;
    	m_N = 0;
    	m_Nom = _T&#40;""&#41;;
    	m_Prenom = _T&#40;""&#41;;
    	m_Adresse = _T&#40;""&#41;;
    	m_nFields = 4;
    	//&#125;&#125;AFX_FIELD_INIT
     
    	m_NomParam = _T&#40;""&#41;;
    	m_nParams = 1;      // précise le nombre de paramêtre ici 1
    	m_nDefaultType = snapshot;
    &#125;
    dans la fonction DoFieldExchange tu écrits
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     void CMyRecordSet&#58;&#58;DoFieldExchange&#40;CFieldExchange* pFX&#41;
    &#123;
    	//&#123;&#123;AFX_FIELD_MAP&#40;CMyRecordSet&#41;
    	pFX->SetFieldType&#40;CFieldExchange&#58;&#58;outputColumn&#41;;
    	RFX_Long&#40;pFX, _T&#40;"&#91;N&#93;"&#41;, m_N&#41;;
    	RFX_Double&#40;pFX, _T&#40;"&#91;Nom&#93;"&#41;, m_Nom&#41;;
    	RFX_Double&#40;pFX, _T&#40;"&#91;Prenom&#93;"&#41;, m_Prenom&#41;;
    	RFX_Double&#40;pFX, _T&#40;"&#91;Adresse&#93;"&#41;, m_Adresse&#41;;
    	//&#125;&#125;AFX_FIELD_MAP
     
                   // if faut définir le paramêtre
    	pFX->SetFieldType&#40;CFieldExchange&#58;&#58;param&#41;;
    	RFX_Double&#40;pFX, _T&#40;"&#91;Nom Param&#93;"&#41;, m_NomParam&#41;;
    &#125;
    Je crois que ça suffit. Mais d'abord je te conseillerais de lire une très bonne doc sur ODBC avec VC++. Une fois que les bases sont assises alors il est plus facile de répondre à des questions plus spécifiques. Je souhaiterais vivement qu'on prolonge la fac Visual C++ sur les bases de données. Merci

    Gabrielly

Discussions similaires

  1. requete avec la valeur NULL
    Par Hinkel dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 12/11/2008, 17h39
  2. requete avec ibquery 'colonne inconnue'???
    Par mvg dans le forum InterBase
    Réponses: 2
    Dernier message: 01/02/2004, 18h45
  3. Pb d'execution de requete avec un script php
    Par ythierrin dans le forum Requêtes
    Réponses: 3
    Dernier message: 22/08/2003, 15h34
  4. Requete avec une sous-requete... Ne fonctionne qu'a moitie..
    Par mythtvtalk.com dans le forum MS SQL Server
    Réponses: 10
    Dernier message: 18/08/2003, 10h54
  5. Requete avec des décimales
    Par Sandrine75 dans le forum MS SQL Server
    Réponses: 5
    Dernier message: 27/06/2003, 11h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo