资源描述:
《在VB中用ODBC API访问数据库》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、一、声明ODBCAPI函数 这些函数都在odbc32.dll中定义了,要在程序中调用这些函数,必须首先对它们进行声明。建立一个模块,在里面写入下列内容:'==声明odbc32.dll中定义的ODBCAPI函数==PublicDeclareFunctionSQLAllocEnvLib"odbc32.dll"(phenv&)AsIntegerPublicDeclareFunctionSQLAllocConnectLib"odbc32.dll"(ByValHenv&,phdbcd&)AsIntegerPublic
2、DeclareFunctionSQLAllocStmtLib"odbc32.dll"(ByValHdbc&,phstmt&)AsIntegerPublicDeclareFunctionSQLConnectLib"odbc32.dll"(ByValHdbc&,ByValszDSN$,ByValcbDSN%,ByValszUID$,ByValcbUID%,ByValszPWD$,ByValcbPWD%)AsIntegerPublicDeclareFunctionSQLColAttributesLib"odbc32.
3、dll"(ByValHstmt&,ByValicol%,ByValfDescType%,ByValrgbDescAsString,ByValcbDescMax%,pcbDesc%,pfDesc&)AsIntegerPublicDeclareFunctionSQLDisconnectLib"odbc32.dll"(ByValHdbc&)AsIntegerPublicDeclareFunctionSQLExecDirectLib"odbc32.dll"(ByValHstmt&,ByValszSqlStr$,ByVa
4、lcbSqStr&)AsIntegerPublicDeclareFunctionSQLFetchLib"odbc32.dll"(ByValHstmt&)AsIntegerPublicDeclareFunctionSQLFreeConnectLib"odbc32.dll"(ByValHdbc&)AsIntegerPublicDeclareFunctionSQLFreeEnvLib"odbc32.dll"(ByValHenv&)AsIntegerPublicDeclareFunctionSQLFreeStmtLib
5、"odbc32.dll"(ByValHstmt&,ByValfOption%)AsIntegerPublicDeclareFunctionSQLGetDataLib"odbc32.dll"(ByValHstmt&,ByValicol%,ByValfCType%,ByValrgbValueAsString,ByValcbValueMax&,pcbValue%)AsIntegerPublicDeclareFunctionSQLNumResultColsLib"odbc32.dll"(ByValHstmt&,pcco
6、l%)AsIntegerPublicDeclareFunctionSQLGetDiagRecLib"odbc32.dll"(ByValHandleType%,ByValHandle&,ByValRecNumber%,Sqlstate%,NativeErrorPtr%,MessageTextAsString,ByValBufferlenchgth%,TextlenchgthPtr%)数据库访问常量和数据源信息常量:'数据库访问常量PublicConstSQL_C_CHARAsLong=1PublicConstSQ
7、L_COLUMN_LABELAsLong=18PublicConstSQL_DROPAsLong=1PublicConstSQL_DRRORAsLong=-1PublicConstSQL_NO_DATA_FOUNDAsLong=100PublicConstSQL_SUCCESSAsLong=0PublicConstSQL_SUCCESS_WITH_INFOAsLong=1PublicConstSQL_ATTR_MAX_LENGTHAsLong=100'数据源信息常量PublicConstDATABASEAsSt
8、ring="newdb"PublicConstDSNAsString="newdb"PublicConstDB_USER_NAMEAsString="sa"PublicConstDB_PASSWORDAsString="sa"'版本号PublicConstVerNumAsString="版本1.0.01"'生成日期PublicConstGenDateAsString="日期2002-0