M
meng_bupt
Unregistered / Unconfirmed
GUEST, unregistred user!
从网上看到的一段程序,但是在BCB6.0下编译时出错:
[Linker Error] Unresolved external '_SQLSetEnvAttr' referenced from D:/TEST/DB/UNIT1.OBJ
[Linker Error] Unresolved external '_SQLConnect' referenced from D:/TEST/DB/UNIT1.OBJ
[Linker Error] Unresolved external '_SQLAllocHandle' referenced from D:/TEST/DB/UNIT1.OBJ
[Linker Error] Unresolved external '_SQLDisconnect' referenced from D:/TEST/DB/UNIT1.OBJ
[Linker Error] Unresolved external '_SQLFreeHandle' referenced from D:/TEST/DB/UNIT1.OBJ
----------------------
SQLHENV henv;
SQLHDBC hdbc;
SQLHSTMT hstmt;
SQLRETURN retcode;
/*Allocate environment handle */
retcode = SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&henv);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{ /* Set the ODBC version environment attribute */
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{ /* Allocate connection handle */
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{/* Set login timeout to 5 seconds. */
SQLSetConnectAttr(hdbc,(void*)SQL_LOGIN_TIMEOUT,5,0);
//这里也报错
/* Connect to data source */
retcode = SQLConnect(hdbc, (SQLCHAR*) "A_DB", SQL_NTS,
(SQLCHAR*) "", SQL_NTS,(SQLCHAR*) "", SQL_NTS);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{/* Allocate statement handle */
ShowMessage("OK");
retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{/* Process data */
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
SQLDisconnect(hdbc);
}
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
}
}
SQLFreeHandle(SQL_HANDLE_ENV, henv);
}
}
那位帮忙改改?要是对数据库查询、增加、修改和删除怎么加入代码?代码怎么写?谢谢。
[Linker Error] Unresolved external '_SQLSetEnvAttr' referenced from D:/TEST/DB/UNIT1.OBJ
[Linker Error] Unresolved external '_SQLConnect' referenced from D:/TEST/DB/UNIT1.OBJ
[Linker Error] Unresolved external '_SQLAllocHandle' referenced from D:/TEST/DB/UNIT1.OBJ
[Linker Error] Unresolved external '_SQLDisconnect' referenced from D:/TEST/DB/UNIT1.OBJ
[Linker Error] Unresolved external '_SQLFreeHandle' referenced from D:/TEST/DB/UNIT1.OBJ
----------------------
SQLHENV henv;
SQLHDBC hdbc;
SQLHSTMT hstmt;
SQLRETURN retcode;
/*Allocate environment handle */
retcode = SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&henv);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{ /* Set the ODBC version environment attribute */
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{ /* Allocate connection handle */
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{/* Set login timeout to 5 seconds. */
SQLSetConnectAttr(hdbc,(void*)SQL_LOGIN_TIMEOUT,5,0);
//这里也报错
/* Connect to data source */
retcode = SQLConnect(hdbc, (SQLCHAR*) "A_DB", SQL_NTS,
(SQLCHAR*) "", SQL_NTS,(SQLCHAR*) "", SQL_NTS);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{/* Allocate statement handle */
ShowMessage("OK");
retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{/* Process data */
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
SQLDisconnect(hdbc);
}
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
}
}
SQLFreeHandle(SQL_HANDLE_ENV, henv);
}
}
那位帮忙改改?要是对数据库查询、增加、修改和删除怎么加入代码?代码怎么写?谢谢。