<ADODB_Recordset>.Open

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Modules > ADODB > ADODB Module Classes > ADODB_Recordset > ADODB_Recordset Methods >

<ADODB_Recordset>.Open

 

Description

 
Opens a database element that gives you access to records in a table, the results of a query, or to a saved Recordset.

 

Syntax

 

<ADODB_Recordset>.Open (sSource, pConnection [, CursorType [, lLockType [, lCommandType]]])

 

Returns

 

None.

 

Parameters

 

Name

Type

Optional

Meaning

sSource

String

No

Specifies a data source.

The source parameter may be one of the following:

An SQL statement

A stored procedure

A table name

...

pConnection

Object

No

An ADODB_ Connection object

lCursorType

Numeric

Yes

A CursorTypeEnum value that specifies the type of cursor to use when opening a Recordset object.

 

Default is %adOpenForwardOnly

lLockType

Numeric

Yes

A LockTypeEnum value that specifies the type of locking on a Recordset object.

 

Default is %adLockReadOnly

lCommandType

Numeric

Yes

Specifies how to evaluate the source parameter. Can be one or more CommandTypeEnum.

 

Default is %adCmdUnknown

 

Remarks

 

Always Close the ADODB_Recordset object after using it, to free system resources

Use <ADODB_Recordset>.Close when finished to use a Recordset

 

Restrictions

 

See also

 

Examples

 

Uses "Console"

Uses "ADODB"

 

String sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & APP_SourcePath & "Biblio.mdb"

 

'---Declare a new pConnection variable and instantiate it in one line

Dim pConn As New ADODB_CONNECTION '[(sConn)]

'---Set connection string

pConn.ConnectionString = sConn

'---Open connection. Connection string is taken from ConnectionString property

pConn.Open

 

If pConn.State = %ADSTATEOPEN Then

 

    Dim pRS   As New ADODB_RECORDSET

    Dim sSql  As String

  

    pRs.CursorLocation = %ADUSECLIENT

 

    sSql = "select * from Authors"

 

    '---

    PrintL "Query is:", sSql

 

    pRs.OPEN sSql, pConn, %ADOPENDYNAMIC%ADLOCKOPTIMISTIC%ADCMDTEXT

 

    If pRS.State = %ADSTATEOPEN Then

      '---Do something with the Recordset

      PrintL "Records found", pRs.RecordCount

 

      '---...

 

      '---Close recordset

      PrintL "  pRecordSet.Close         :", pRS.CLOSE

    else

      '---Something Wrong the Recordset

      PrintL "  Something wrong with the recordset"

    End If

 

    '---Close Connection

    PrintL "  pConnection.Close        :", pConn.CLOSE

 

Else

      PrintL "-It was not possible to open a connection-" In %CCOLOR_FLIGHTRED

End If

 

PrintL "---Press a key to finish---"

WaitKey