7. Get the Data in each field of the Fetched row - SQLGetData
Dim bPerform As Integer, iStatus As Integer Dim sData As String * MAX_DATA_BUFFER Dim lOutLen As Long
bPerform = SQLFetch(glStmt)
Do While bPerform bPerform = SQLFetch(lStmt) ' Get the next row of data If bPerform = SQL_SUCCESS Then‘ If rows of data available bPerform = True
' Get Author Name - iColumn = 1 for first field i.e. name in sSQL iStatus = SQLGetData(glStmt, iColumn, 1, sData, MAX_DATA_BUFFER, lOutLen)
' lOutlen = length of the valid data in sData ' Data value will be = Left$(sData, lOutlen), lOutlen = -1 if no data or Null data
' Get Location - iColumn = 2 for second field i.e. location in sSQL iStatus = SQLGetData(glStmt, iColumn, 1, sData, MAX_DATA_BUFFER, lOutLen)
' Add the Field Data to Correponding Data Display Controls for this row Else bPerform = False' No more rows available End If Loop
'Release the ODBC Statement Handle bPerform = SQLFreeStmt(glStmt, SQL_DROP) ______________________________________________________________
8. Release the ODBC Statement Handle - SQLFreeSTmt
Code in Step 7. ______________________________________________________________
******************************************************************* The steps 9 - 11 are for Disconnecting from the SQL Server DataBase *******************************************************************
9. Disconnect from ODBC Database - SQLDisconnect
iStatus = SQLDisconnect(glDbc) ______________________________________________________________
10. Release the ODBC Database Handle - SQLFreeConnect
iStatus = SQLFreeConnect(glDbc) ______________________________________________________________
11. Release the ODBC Environment Handle - SQLFreeEnv
iStatus = SQLFreeEnv(glEnv) ______________________________________________________________
*********************************************************************** The following entries are required in the ODBCAPI module ***********************************************************************
' ODBC Variables and Constants Global glEnv As Long Global glDbc As Long Global sSQL As String Global Const MAX_DATA_BUFFER = 255 Global Const SQL_SUCCESS = 0 Global Const SQL_SUCCESS_WITH_INFO = 1 Global Const SQL_ERROR = -1 Global Const SQL_NO_DATA_FOUND = 100 Global Const SQL_CLOSE = 0 Global Const SQL_DROP = 1 Global Const SQL_CHAR = 1 Global Const SQL_NUMERIC = 2 Global Const SQL_DECIMAL = 3 Global Const SQL_INTEGER = 4 Global Const SQL_SMALLINT = 5 Global Const SQL_FLOAT = 6 Global Const SQL_REAL = 7 Global Const SQL_DOUBLE = 8 Global Const SQL_VARCHAR = 12 Global Const SQL_DATA_SOURCE_NAME = 6 Global Const SQL_USER_NAME = 8
'ODBC Declarations 'The hWnd is a Long in Windows 95 & Windows NT
直接通过ODBCAPI访问SQL数据库二 |