CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2005
    Posts
    76

    clear me about cursor type

    I work with vb6 and access database and i need only read recordset.

    my conn:

    Public Sub APRI_CONNESSIONE3()

    On Error GoTo Err_SomeName

    If Not CONN3 Is Nothing Then
    If CONN3.State = 1 Then
    CONN3.Close
    End If
    Set CONN3 = Nothing
    End If

    Set CONN3 = New ADODB.Connection
    With CONN3
    .CursorLocation = adUseClient
    .Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\REPORT_L0928\DATABASE\" & MIO_DB & "-L0928_TEST.mdb;Persist Security Info=False"
    End With

    Exit_SomeName:
    Exit Sub

    Err_SomeName:
    MsgBox Err.Number & Err.Description
    Resume Exit_SomeName

    End Sub

    my open recorset:

    Public Function ExecuteSQL(SQL)

    CLEAN_UP

    Set RST0 = New ADODB.Recordset
    With RST0
    .CursorLocation = adUseServer
    DoEvents
    'test1
    '.Open SQL, CONN3, adOpenStatic, adLockReadOnly, adCmdText
    'test2
    '.Open SQL, CONN3, adOpenDynamic, adLockOptimistic, adCmdText
    'test3
    .Open SQL, CONN3, adOpenForwardOnly, adLockReadOnly, adCmdText
    'test4
    .Open SQL, CONN3, adOpenStatic, adLockOptimistic, adCmdText

    End With

    End Function

    Public Function CLEAN_UP()

    If Not RST0 Is Nothing Then
    If RST0.State = 1 Then
    RST0.Close
    End If
    Set RST0 = Nothing
    End If

    End Function


    i have tested all 3 .open statement but not sure wat i need really.

    note:
    - approx records in table are 1.500.xxx
    - i have eindexed all fileds in clausole Where

    - here one of mine query, for example:

    SQL = "SELECT DT FROM L0_SI WHERE (CONTAB='" & TEST_CONTAB & "') GROUP BY DT"
    ExecuteSQL (SQL)
    Last edited by sal21; January 25th, 2012 at 03:07 PM.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: clear me about cursor type

    Read this. It describes the various options:

    Code:
    'Syntax:
    RS.Open "Source" (a table or sql statement), "Connection", "Cursor Type", "Record Locking Type", "Type of Open" (Table, text, stored procedure, etc.
    
    'Ex:
    RS.Open "SELECT * FROM Table1;"
    'The source is to select all fields and records from the table called "Table1"
    
    'Ex:
    RS.Open "SELECT * FROM Table1;", CN
    'CN is your connection object to the database so it knows what database and location, etc.
    
    'Ex:
    RS.Open "SELECT * FROM Table1;", CN, adOpenKeyset
    'There are 4 types of cursor types (CursorTypeEnum):
    adOpenForwardOnly - Default. Uses a forward-only cursor. Identical to a static cursor, except that you can only scroll forward through records. This improves performance when you need to make only one pass through a Recordset.
    adOpenDynamic  - Uses a dynamic cursor. Additions, changes, and deletions by other users are visible, and all types of movement through the Recordset are allowed, except for bookmarks, if the provider doesn't support them.
    adOpenKeyset - Uses a keyset cursor. Like a dynamic cursor, except that you can't see records that other users add, although records that other users delete are inaccessible from your Recordset. Data changes by other users are still visible.
    adOpenStatic - Uses a static cursor. A static copy of a set of records that you can use to find data or generate reports. Additions, changes, or deletions by other users are not visible.
    
    'Ex:
    RS.Open "SELECT * FROM Table1;", CN, adOpenKeyset, adLockOptimistic
    'There are 4 basic types of recordlocking:
    adLockReadOnly - Indicates read-only records. You cannot alter the data.
    adLockPessimistic - Indicates pessimistic locking, record by record. The provider does what is necessary to ensure successful editing of the records, usually by locking records at the data source immediately after editing.
    adLockOptimistic - Indicates optimistic locking, record by record. The provider uses optimistic locking, locking records only when you call the Update method.
    adLockBatchOptimistic - Indicates optimistic batch updates. Required for batch update mode.
    
    'Ex:
    RS.Open "SELECT * FROM Table1;", CN, adOpenKeyset, adLockOptimistic, adCmdText
    'Options: A Long value that indicates how the provider should evaluate the Source argument
    'There are a few options for Options: CommandTypeEnum -
    adCmdText - Evaluates CommandText as a textual definition of a command or stored procedure call.
    adCmdTable - Evaluates CommandText as a table name whose columns are all returned by an internally generated SQL query.
    adCmdStoredProc - Evaluates CommandText as a stored procedure name.
    adCmdUnknown - Default. Indicates that the type of command in the CommandText property is not known.
    adCmdFile - Evaluates CommandText as the file name of a persistently stored Recordset. Used with Recordset.Open or Requery only.
    adCmdTableDirect - Evaluates CommandText as a table name whose columns are all returned. Used with Recordset.Open or Requery only. To use the Seek method, the Recordset must be opened with adCmdTableDirect. 
    
    'And ExecuteOptionEnum - 
    adAsyncExecute - Indicates that the command should execute asynchronously. 
    adAsyncFetch - Indicates that the remaining rows after the initial quantity specified in the CacheSize property should be retrieved asynchronously.
    adAsyncFetchNonBlocking - Indicates that the main thread never blocks while retrieving. If the requested row has not been retrieved, the current row automatically moves to the end of the file. 
    adExecuteNoRecords - Indicates that the command text is a command or stored procedure that does not return rows (for example, a command that only inserts data). If any rows are retrieved, they are discarded and not returned. 
    adExecuteStream - Indicates that the results of a command execution should be returned as a stream. 
    adExecuteRecord - Indicates that the CommandText is a command or stored procedure that returns a single row which should be returned as a Record object.
    adOptionUnspecified - Indicates that the command is unspecified.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: clear me about cursor type

    Sal21, please use CODE tags when posting code. It makes your code much easier to read and follow.

  4. #4
    Join Date
    Jan 2005
    Posts
    76

    Talking Re: clear me about cursor type

    Quote Originally Posted by HanneSThEGreaT View Post
    Sal21, please use CODE tags when posting code. It makes your code much easier to read and follow.
    Ok for the future.. sorry me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured