מצאתי את זה אבל
אני לא מבין מזה כלום..:
#include <windows.h> #include <sqlext.h> #include<sql.h> #include <stdio.h> int main(void) { HENV hEnv =NULL;//for allocating memory usingSQLAllocEnv HDBC hDBC =NULL;//connection handle HSTMT hStmt =NULL;//statement handle UCHAR szDSN[SQL_MAX_DSN_LENGTH]="cc"; UCHAR*szUID ="pri";//username of the database UCHAR*szPasswd ="pri";//password of the database CHAR szModel[128]; SDWORD cbModel; UCHAR szSqlStr[]="Select *From cchecktab";//cchecktab is the table name in my database RET CODE retcode; int i,j,no=1; //Allocate memory for ODBC Environment handle SQLAllocEnv (&hEnv); SQLAllocConnect (hEnv,&hDBC); //connecting to the database retcode =SQLConnect(hDBC,szDSN,SQL_NTS,szUID,SQL_NTS,szPasswd,SQL_NTS); //”retcode”will hold ‘1’if connection is established else ’-1’ printf("Connecting to the database\n"); for(i=0;i<10;i++) { for(j=0;j<100;j++); printf ("."); } if (retcode ==SQL_SUCCESS ||retcode ==SQL_SUCCESS_WITH_INFO) { retcode =SQLAllocStmt (hDBC,&hStmt); retcode =SQLPrepare (hStmt,szSqlStr,sizeof (szSqlStr)); retcode =SQLExecute (hStmt); printf("\nReading the records\n"); SQLBindCol(hStmt,no,SQL_C_CHAR,szModel,sizeof(szModel),&cbModel); SQLBindCol(hStmt,no+1,SQL_C_CHAR,szModel1,sizeof(szModel1),&cbModel1); retcode =SQLFetch (hStmt); while (retcode ==SQL_SUCCESS ||retcode ==SQL_SUCCESS_WITH_INFO) { printf ("\t%s\n",szModel); r etcode =SQLFetch (hStmt); } SQLFreeStmt (hStmt,SQL_DROP); SQLDisconnect (hDBC); } els e { pr intf("Cannot read the database\n"); } SQLFreeConnect (hDBC); SQLFreeEnv (hEnv); return 0; }