应该不能吧,SQL怎么能解释C的代码呢?

解决方案 »

  1.   

    不行吧。
    c语言中倒是可以使用sql语句
    如:
    main()
    {
    exec sql include sqlca
    exec sql begin declare section
      char prname[20];
      char productno[8];exec sql end declare sectionprintf("Input producno:");
    scanf("%s",&producno);exec sql select prname
             from product
             where productno=:productno
             into :prname;printf("Productname: %s\n",prname);exit();}
      

  2.   

    c 语言可以内嵌sql的
    你在SQL 2000的帮助里找ESQL/C就可以找到。
    有例程
    我贴一点给你
    int main(int argc, char *argv[])
        {
        LOGINREC*   login;      // login rec pointer
        DBPROCESS*  dbproc;     // SQL Server connection structure pointer    char        cmd[150];   // command buffer
        char        server[30]; // server name buffer
        int         x = 1;      // command line counter
        STATUS      retc;       // return code    const char* sqlversion; // pointer for version string    *server = '\0';         // null start these two buffers
        *cmd = '\0';    if(argc == 1)           // if no server name, request it
            {
        printf("Enter Server Name: ");
        gets(server);
            }
        else                    // else it was input as first arg
           strcpy(server,argv[1]);    if(argc < 2)            // if no login id, request it
            {
            printf("Enter User Name: ");
            gets(cmd);
            }
        else                    // otherwise it was input as second arg.
            strcpy(cmd,argv[2]);    // check to see if communications layer was loaded (DOS ONLY)
        if((sqlversion = dbinit()) == (BYTE *)NULL)
            {
            // DOS TSR (DBNMPIPE.EXE) is not loaded, don't bother going any farther
            printf("Error in DB-Library initialization, exiting\n");
            return 1;
            }
        else
            printf("DB-Library version: %s\n",sqlversion);  // print dblib version    dbsettime(30);          // set timeouts to 30 seconds
        
        // set error/msg handlers for this program
        dbmsghandle((DBMSGHANDLE_PROC)msg_handler);
        dberrhandle((DBERRHANDLE_PROC)err_handler);    login = dblogin();      // get a login rec    DBSETLUSER(login,cmd);  // set login id
        DBSETLHOST(login,"SQL EXAMPLE");    // set host name for sp_who
        DBSETLVERSION(login, DBVER60);
        // To use secure, or trusted, connection, uncomment the following line.
        // DBSETLSECURE (login);    // open connection to requested server.  Pass null server name for local
        // connection, if name not entered.
        if((dbproc = dbopen(login,(*server) ? server : (char *)NULL)) == (DBPROCESS *)NULL)
            {
            // no one answered, so couldn't connect or error occurred
            printf("Login failed\n");
            return 1;
            }
        else
            {
            // loop on command input until quit or exit appears in first 4 bytes.
            while((strnicmp(cmd,"quit",4) != 0) && (strnicmp(cmd,"exit",4)!=0))
                {
                printf("%d> ", x++);                // print command prompt
                gets(cmd);                          // get command
                if(strnicmp(cmd,"go",2) == 0)       // is it go
                    {
                    if(dbsqlexec(dbproc) == FAIL)   // execute command
                        {
                        // problem occurred, just try another command
                        printf("Error in executing command batch!\n");
                        x = 1;
                        continue;
                        }
                    // command executed correctly, get results information
                    while((retc = dbresults(dbproc)) != NO_MORE_RESULTS)
                        {
                        if (retc == FAIL)           // if error get out of loop
                            break;                    // headers and data could be printed here with only two
                        // function calls, dbprhead(dbproc), and dbprrow(dbproc),
                        // which would output the headers, and all the data to
                        // standard output.  However, that isn't very informative
                        // toward understanding how this data is obtained and
                        // processed, so I do it the hard way, one column at a time.                    PrintHeaders(dbproc);       // print header data                    // loop on each row, until all read
                        while((retc= dbnextrow(dbproc))!=NO_MORE_ROWS)
                            {
                            if(retc == FAIL)        // if fail, then clear
                                {                   // connection completely, just
                                dbcancel(dbproc);   // in case.
                                break;
                                }
                            else
                                PrintRow(dbproc);   // else print the current row
                            }                    if (DBCOUNT(dbproc) == 1L)  // print the row count
                            printf("(1 row effected)\n");
                        else
                            printf("(%ld rows effected)\n",DBCOUNT(dbproc));                    }                           // end while(dbresults())                x = 1;                      // reset command line counter
                    }
                else
                    {
                    strcat(cmd," ");            // go not detected, so put space
                    dbcmd(dbproc,cmd);          // between each command and set in
                    }                           // dbproc.            } // end while()        dbclose(dbproc);                // quit/exit input, close connection        // print adios and exit.
            printf("SQL Server Connection to %s closed, bye bye.\n",server);
            return 0;
            }
        }/*
      

  3.   

    FROM  MSDN:Setting Up the nsqlprep Precompiler
    Before you run the nsqlprep precompiler, do the following:The nsqlprep precompiler uses your compiler to process header files Set the INCLUDE environment variable to include the full path where the Sqlca.h and Sqlda.h ESQL/C header files are located and set the LIB environment variable to include the full path where the library files are located. There are several ways to accomplish this, including either: 
    Issuing a SET statement at the command prompt, such as 
    SET INCLUDE = C\Mssql17\DevTools\INCLUSE; %include%SET LIB = C\Mssql17\DevTools\LIB; %LIB%At the command prompt, first running Vcvar32.bat (in the \Program Files\Microsoft Visual Studio\VC98\Bin directory) and then running setenv.bat (in \Mssql17\DevTools\Samples\Esqlc directory). 
    The nsqlprep precompiler automatically includes these header files in the C programs it creates. Do not explicitly include them (by using #include) in an Embedded SQL program. To enable communication with Microsoft&reg; SQL Server&#8482; 2000, ensure that an appropriate Net-Library is loaded or available on the path when precompiling with the /DB and /PASS options. For example, the Named Pipes Net-Library for the Microsoft Windows NT&reg; operating system (Intel&reg; platform) is Dbnmpntw.dll, and the Named Pipes Net-Library for the Microsoft MS-DOS&reg; operating system is the Dbnmpipe.exe TSR.