在做ms sqlServer 数据库编程练习的时候,为了能够看一下sqlServer的联机丛书中的例子跑起来是什么样子,就拷了里面的一个源代码来跑,没想到竟然不能通过vc6的编译!
代码如下:
- #include <stdio.h>
- #include <string.h>
- #include <windows.h>
- #include <sql.h>
- #include <sqlext.h>
- #include <odbcss.h>
- #define MAXBUFLEN 255
- sqlHENV henv = sql_NULL_HENV;
- sqlHDBC hdbc1 = sql_NULL_HDBC;
- sqlHSTMT hstmt1 = sql_NULL_HSTMT;
- int main() {
- RETCODE retcode;
- // sqlBindCol variables
- sqlCHAR szName[MAXNAME+1];
- // sqlINTEGER cbName;
- // Allocate the ODBC Environment and save handle.
- retcode = sqlAllocHandle (sql_HANDLE_ENV, NULL, &henv);
- // Notify ODBC that this is an ODBC 3.0 application.
- retcode = sqlSetEnvAttr(henv, sql_ATTR_ODBC_VERSION,
- (sqlPOINTER) sql_OV_ODBC3, sql_IS_INTEGER);
- // Allocate an ODBC connection and connect.
- retcode = sqlAllocHandle(sql_HANDLE_DBC, henv, &hdbc1);
- retcode = sqlConnect(hdbc1,
- "test", sql_NTS,"jiiming", "123", sql_NTS);
- // Allocate a statement handle.
- retcode = sqlAllocHandle(sql_HANDLE_STMT, hdbc1, &hstmt1);
- // Execute an sql statement directly on the statement handle.
- // Uses a default result set because no cursor attributes are set.
- unsigned char *sqlstr="select * from SC";
- retcode = sqlExecDirect(hstmt1,
- sqlstr, 17);
- // Simplified result set processing. Fetch until sql_NO_DATA.
- // The application can be compiled with the sqlBindCol line
- // commented out to illustrate sqlGetData, or compiled with the
- // sqlGetData line commented out to illustrate sqlBindCol.
- // This sample shows that sqlBindCol is called once for the
- // result set, while sqlGetData must be called once for each
- // row in the result set.
- // retcode = sqlBindCol(hstmt1, 1, sql_C_CHAR,
- // szName, MAXNAME, &cbName);
- while ( (retcode = sqlFetch(hstmt1) ) != sql_NO_DATA ) {
- sqlINTEGER Sno,Cno,Grade;
- sqlINTEGER Snolen,Cnolen,Gradelen;
- // sqlGetData(hstmt1, szName, &cbName);
- sqlGetData(hstmt1,1,sql_C_LONG,&Sno, &Snolen);
- sqlGetData(hstmt1,2,&Cno, &Cnolen);
- sqlGetData(hstmt1,3,&Grade, &Gradelen);
- printf("Sno= %d/tCno = %d/tGrade = %d",Sno,Grade);
- }
- /* Clean up.*/
- sqlFreeHandle(sql_HANDLE_STMT, hstmt1);
- sqldisconnect(hdbc1);
- sqlFreeHandle(sql_HANDLE_DBC, hdbc1);
- sqlFreeHandle(sql_HANDLE_ENV, henv);
- return(0);
- }
这段代码我只改了数据库名字,用户名,密码,以及结果集的处理部分,没想到不能通过编译,错误如下:
) : 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] 举报,一经查实,本站将立刻删除。