Data Source Class to access Data Environment 
Author Message
 Data Source Class to access Data Environment

I'm using VB6 SP-1
ADO 2.0

I'm trying to create a component (activex.dll) for all my data access
in an application I'm developing.

This component has a Private Data Environment as well as a public
DataSource class that I'm binding controls to in my main program
component.

This works wonderfully and enables me to distribute all of my data
access seperately from the rest of my application.

The problem I have starts when I try to use Child Commands in my data
environment.

As you know, you can create child commands to create a hierarchical
recordset.  

If you have a data environment in the same project, and therefore
within scope of your forms, you bind can Grid1 to the parent command
object and bind Grid2 to the child command object.  The result is a
master and detail grid relationship that requires no event coding
within the grids.

I want to duplicate this behavior, but through a Data Source Class.

I have having difficulties getting the detail grid to refresh properly
when I switch records on the master grid.

Sample code is below.

Thank you for your help!

Jeremy Markman

Here is some code I have tried:

Data Source Class:
(cmdDoctorView is a child command to cmdPracticeView)
Option Explicit
' TODO: Declare local ADO Recordset object. For example:
'Private WithEvents rs As ADODB.Recordset

Private GazEnv As envGazelle
Private WithEvents rs As ADODB.Recordset
Dim rs2 As Variant

Private Sub Class_GetDataMember(DataMember As String, Data As Object)
    ' TODO:  Return the appropriate recordset based on DataMember. For
example:

    Select Case DataMember
    Case ""             ' Default
        Set Data = rs
    Case "cmdPracticeView"
        Set Data = rs
    Case "cmdDoctorView"
        Set Data = rs2
    Case Else           ' Default
        Set Data = Nothing
    End Select
End Sub

Private Sub Class_Initialize()
        Set GazEnv = New envGazelle
        Set rs = GazEnv.rscmdPracticeView
        rs.Open
        DataMembers.Add "cmdPracticeView"
        DataMembers.Add "cmdDoctorView"
End Sub

Private Sub Class_Terminate()
    If rs.State = ADODB.adStateOpen Then
        rs.Close
        Set rs = Nothing
        Set rs2 = Nothing
        Set GazEnv = Nothing
    End If
End Sub

Private Sub rs_MoveComplete(ByVal adReason As ADODB.EventReasonEnum,
ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal
pRecordset As ADODB.Recordset)
        Set rs2 = rs("cmdDoctorView").Value
End Sub

Code to bind Grids at runtime:
Dim m_PracticeView as GazDataSource.clsDSPracticeView

Private Sub Form_Load()
    Set m_PracticeView = New GazDataSource.clsDSPracticeView

    With TDBGrid1
        .DataMember = "cmdPracticeView"
        Set .DataSource = m_PracticeView
    End With
    With TDBGrid2
        .DataMember = "cmdDoctorView"
        Set .DataSource = m_PracticeView
    End With

End Sub



Mon, 09 Jul 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Creating a control class that can be a data binding data source

2. Visual Basic 4.0a error with ORACLE Data source accessing BLOB data

3. error 3265 when accessing odbc data source through data control

4. Access virtually any data source : Report off in-memory application data

5. Syntax for importing data into an Access table from an ODBC data source

6. DataCombo Parameterized Data Environment Query Source?

7. Data Environment returns CLASS NOT REGISTERED!!

8. Webclass + Class Modules + Data Environment

9. class not registered in Data Environment

10. Data updating class source codes...

11. Class as data source

12. Class Module as data source (sort of)

 

 
Powered by phpBB® Forum Software