Программирование в IIS


Пример 1.11


'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

'GetADORecordSet

'Sends SQL command to datasource and returns

'an ADO Recordset to the function consumer

'

'in: vsSource - SQL string to execute

'out: returns true on success, false otherwise

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Private Function GetADORecordSet(ByVal vsSource As String) _

As ADODB.Recordset

On Error GoTo Sub_Error_Handler

Const ERROR_MESSAGE_INFO = "GetADORecordSet"

Dim rsRequested As ADODB.Recordset

Dim cmdRequested As ADODB.Command

'establish connection

If m_Connection.State <> adStateOpen Then

Err.Raise 1001, ERROR_MESSAGE_INFO, _

"Connection Object is not open. Database connect be opened."

End If

'establish command

Set cmdRequested = CreateObject("ADODB.Command")

Set cmdRequested.ActiveConnection = m_Connection

'set up command object

cmdRequested.CommandType = adCmdText

cmdRequested.CommandText = vsSource

'Create instance of Recordset object

Set rsRequested = cmdRequested.Execute

'return Recordset

If Not rsRequested Is Nothing Then

If rsRequested.State = adStateOpen Then

Set GetADORecordSet = rsRequested

Else

'rsRequested state is not open

Err.Raise 1001, ERROR_MESSAGE_INFO, _

" Recordset state is not open " & vsSource

End If

Else

'rsRequested is nothing error

Err.Raise 1001, ERROR_MESSAGE_INFO, _

" Recordset object is nothing " & vsSource

End If

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sub_Exit_Done:

'return value

On Error Resume Next

'destroy objects

Set rsRequested = Nothing

Set cmdRequested = Nothing

Exit Function

Sub_Error_Handler:

ProcessErr " Failure obtaining Recordset."

End Function




- Начало -  - Назад -  - Вперед -