Results 1 to 3 of 3

Thread: Getting a Datagrid to Refresh

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    316
    I am using a datagrid to return information to me when I click a button on a form. Can anyone provide help from the code below?

    Code:
    Option Explicit
    Dim cn As New ADODB.Connection
    
    
    Private Sub Form_Load()
    
    Set cn = New ADODB.Connection
    ' The ConnectionString contains the path of the 'database.
        
        With cn
            .Provider = "Microsoft.Jet.OLEDB.4.0"
            .ConnectionString = "Data Source= C:\Inetpub\wwwroot\main\db\service.mdb"
            .Open
        End With
    
    End Sub
    
    
    Private Sub cmdRun_Click()
    
        Dim rsState As New ADODB.Recordset
        Dim sSql As String
        
        sSql = "Select * from tblRequests"
        
        ' Open recordset.
        rsState.Open sSql, cn, adOpenStatic, adLockOptimistic
        
        Debug.Print rsState.RecordCount
        
        Set DataGrid1.DataSource = rsState
        
        DataGrid1.Refresh
    
    End Sub
    Using VS 6 Enterprise w/ SP5 & Windows 2000 Professional

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    A lot of people have trouble with datagrids, especially the refresh method. I would strongly suggest you look at using the dataenvironment or at least an adodc control, though i would strongly recommend the former.

    That way you can set the data bindings and retrieve the field data at runtime. This also gives you more power over what data is displayed.


    Things I do when I am bored: DotNetable

  3. #3
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Worldwide in the Sun
    Posts
    566
    Try This


    Put this statement before the .Open

    .CursorLocation = adUseClient


    Cheers
    Ray
    Ray

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