微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ms SqlServer编程的疑问

 在做ms sqlServer 数据库编程练习的时候,为了能够看一下sqlServer的联机丛书中的例子跑起来是什么样子,就拷了里面的一个代码来跑,没想到竟然不能通过vc6的编译!

     代码如下:

Code:
  1. #include <stdio.h>  
  2. #include <string.h>  
  3. #include <windows.h>  
  4. #include <sql.h>  
  5. #include <sqlext.h>  
  6. #include <odbcss.h>  
  7.   
  8. #define MAXBUFLEN   255  
  9.   
  10. sqlHENV      henv = sql_NULL_HENV;  
  11. sqlHDBC      hdbc1 = sql_NULL_HDBC;       
  12. sqlHSTMT      hstmt1 = sql_NULL_HSTMT;  
  13.   
  14. int main() {  
  15.    RETCODE retcode;  
  16.    // sqlBindCol variables  
  17.    sqlCHAR      szName[MAXNAME+1];  
  18.  //  sqlINTEGER   cbName;  
  19.   
  20.     // Allocate the ODBC Environment and save handle.  
  21.    retcode = sqlAllocHandle (sql_HANDLE_ENV, NULL, &henv);  
  22.    // Notify ODBC that this is an ODBC 3.0 application.  
  23.    retcode = sqlSetEnvAttr(henv, sql_ATTR_ODBC_VERSION,  
  24.                      (sqlPOINTER) sql_OV_ODBC3, sql_IS_INTEGER);  
  25.    // Allocate an ODBC connection and connect.  
  26.    retcode = sqlAllocHandle(sql_HANDLE_DBC, henv, &hdbc1);  
  27.    retcode = sqlConnect(hdbc1,  
  28.             "test"sql_NTS,"jiiming""123"sql_NTS);  
  29.      
  30.    // Allocate a statement handle.  
  31.    retcode = sqlAllocHandle(sql_HANDLE_STMT, hdbc1, &hstmt1);  
  32.    // Execute an sql statement directly on the statement handle.  
  33.    // Uses a default result set because no cursor attributes are set.  
  34.    unsigned char *sqlstr="select * from SC";  
  35.    retcode = sqlExecDirect(hstmt1,  
  36.                      sqlstr, 17);  
  37.   
  38.    // Simplified result set processing. Fetch until sql_NO_DATA.  
  39.    // The application can be compiled with the sqlBindCol line  
  40.    // commented out to illustrate sqlGetData, or compiled with the  
  41.    // sqlGetData line commented out to illustrate sqlBindCol.  
  42.    // This sample shows that sqlBindCol is called once for the  
  43.    // result set, while sqlGetData must be called once for each  
  44.    // row in the result set.  
  45.   
  46. //   retcode = sqlBindCol(hstmt1, 1, sql_C_CHAR,  
  47.  //                 szName, MAXNAME, &cbName);  
  48.    while ( (retcode = sqlFetch(hstmt1) ) != sql_NO_DATA ) {  
  49.         sqlINTEGER Sno,Cno,Grade;  
  50.         sqlINTEGER Snolen,Cnolen,Gradelen;  
  51.    //   sqlGetData(hstmt1, szName, &cbName);  
  52.         sqlGetData(hstmt1,1,sql_C_LONG,&Sno, &Snolen);  
  53.         sqlGetData(hstmt1,2,&Cno, &Cnolen);  
  54.         sqlGetData(hstmt1,3,&Grade, &Gradelen);  
  55.         printf("Sno= %d/tCno = %d/tGrade = %d",Sno,Grade);  
  56.    }  
  57.   
  58.    /* Clean up.*/  
  59.    sqlFreeHandle(sql_HANDLE_STMT, hstmt1);  
  60.    sqldisconnect(hdbc1);  
  61.    sqlFreeHandle(sql_HANDLE_DBC, hdbc1);  
  62.    sqlFreeHandle(sql_HANDLE_ENV, henv);  
  63.   
  64.    return(0);  
  65. }  

        这段代码我只改了数据库名字用户名密码,以及结果集的处理部分,没想到不能通过编译,错误如下:

) : error C2664: 'sqlConnect' : cannot convert parameter 2 from 'char [5]' to 'unsigned char *'

        Types pointed to are unrelated; conversion requires reinterpret_cast,C-style cast or function-style cast

 : error C2440: 'initializing' : cannot convert from 'char [17]' to 'unsigned char *'

        Types pointed to are unrelated; conversion requires reinterpret_cast,C-style cast or function-style cast

         大家帮忙看看,这是没什么呀?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐