Be careful, the locktype of the disconected recordset must be
adlockbatchoptimistic
-----Mensaje original-----
De: Joseph Kaffenberger <jkaffen@n...>
Para: professional vb <pro_vb@p...>
Fecha: Lunes, 18 de Septiembre de 2000 05:57 a.m.
Asunto: [pro_vb] Connected vs DisConnected Recordset for Data Binding
>I have created a Class to act as the datasource for test purposes the
>datagrid control. I fill the rsFormulaID using a SQL call to a MS Access
>database. If I pass the rset created from the Access database directly
>the DataGrid doesn't get populated with the data. If if loop thru the
>Access created (connected) rset to populate a disconnected rset (rsNames)
>the DataGrid is populated. Connected vs Disconnected is the only thing I
>can think of that's different from the two senarios.
>
>Why doesn't the rset "Connected" populate the datagrid control.
>
>Code:
>Form Code:
>Option Explicit
>Private datFormulaID As clsDataSource
>
>Private Sub Form_Load()
> Set datFormulaID = New clsDataSource
> DataGrid1.DataMember = "FormulaID"
> Set DataGrid1.DataSource = datFormulaID
> Label1.Caption = datFormulaID.RecordCount
>End Sub
>
>DataSource Class Code:
>Option Explicit
>
>Private WithEvents rsNames As ADODB.Recordset
>Private WithEvents rsFormulaID As ADODB.Recordset
>Private objConnection As ADODB.Connection
>Dim strConnect As String
>Dim strSQL As String
>______________________________________________________
>Private Sub Class_Initialize()
>
> 'Prepare Connection
> Set objConnection = New ADODB.Connection
> strConnect = "Valid Connection Here"
>
> objConnection.Open strConnect 'Valid Connection to Database
>
> ' Add the names of the new datamember to the DataMember collection
> ' This allows other objects to see the available DataMembers
> DataMembers.Add "FormulaID"
> DataMembers.Add "TestItems"
>
> Set rsNames = New ADODB.Recordset
> << The Disconnected RS. >>
> With rsNames
> .Fields.Append "ID", adBSTR, 6
> .Fields.Append "Name", adBSTR, 255
> .CursorType = adOpenStatic
> .LockType = adLockOptimistic
> .Open
> End With
>
> strSQL = "SELECT Field1, Field2 " _
> & " FROM Table WHERE Condition"
>
> Set rsFormulaID = New ADODB.Recordset
> rsFormulaID.Open strSQL, objConnection, adOpenStatic, adLockOptimistic
>
> Dim i As Integer
>
> For i = 1 To rsFormulaID.RecordCount
> rsNames.AddNew
> rsNames!ID = Left(rsFormulaID!FormulaID, 6)
> rsNames!Name = rsFormulaID!ProductName
> rsNames.Update
> rsFormulaID.MoveNext
> Next
>
> rsNames.MoveFirst
> rsFormulaID.MoveFirst
>
>End Sub
>
>Private Sub Class_GetDataMember(DataMember As String, Data As Object)
>
> Select Case DataMember
> Case "" ' Default
> Set Data = rsNames
> Case "FormulaID"
> Set Data = rsFormulaID
> End Select
>End Sub
>
>