Results 1 to 5 of 5

Thread: datagrid with recordset

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    17

    datagrid with recordset

    hello evrybody
    i'm trying to connect a datagrid to a recordset using this code:

    VB Code:
    1. Dim WithEvents cn As ADODB.Connection
    2. Dim WithEvents rs As ADODB.Recordset
    3. private sub form_load()
    4. Set rs = New ADODB.Recordset
    5. Set cn = New ADODB.Connection
    6. cn.Open "Provider= Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "/workers.mdb;"
    7.  
    8. rs.Open "select workers.* from workers", cn, adOpenKeyset, adLockOptimistic
    9. Set DataGrid1.DataSource = rs
    10. DataGrid1.Refresh
    11. end sub

    There is no error messege, but the datagrid stays empty.
    what could by wrong?

  2. #2
    Member
    Join Date
    Dec 2004
    Posts
    49

    Re: datagrid with recordset

    There should be an error message, because you are using a forward slash instead of a backslash in the file to open :

    VB Code:
    1. cn.Open "Provider= Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "/workers.mdb;"

    Could be you used entered it wrong here, in that case, are you sure there is data in the database?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    17

    Re: datagrid with recordset

    well, i don't think this is the problem...
    the recordset is working, if I'm to search or disply values in it in any other way, but the datagrid is not responding to this.
    thank you anyway
    daniel

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: datagrid with recordset

    I believe you need to use Client Side cursor when data binding.

    VB Code:
    1. cn.Open "Provider= Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "/workers.mdb;"
    2.  
    3. rs.CursorLocation = adUseClient
    4.  
    5. rs.Open "select workers.* from workers", cn, adOpenStatic, adLockOptimistic

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    17

    Re: datagrid with recordset

    thank you very much! it solved it...

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