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", SQL_NTS, "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, 1, SQL_C_CHAR, szName, MAXNAME, &cbName);  
  52.         SQLGetData(hstmt1,1,SQL_C_LONG,&Sno,0, &Snolen);  
  53.         SQLGetData(hstmt1,2,SQL_C_LONG,&Cno,0, &Cnolen);  
  54.         SQLGetData(hstmt1,3,SQL_C_LONG,&Grade,0, &Gradelen);  
  55.         printf("Sno= %d/tCno = %d/tGrade = %d",Sno,Cno,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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值