PDA

Click to See Complete Forum and Search --> : Getting a Datagrid to Refresh


bedowin
Nov 20th, 2000, 02:58 PM
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?


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

davidrobin
Nov 21st, 2000, 07:26 AM
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.

marex
Nov 21st, 2000, 08:22 AM
Try This


Put this statement before the .Open

.CursorLocation = adUseClient


Cheers
Ray