Results 1 to 4 of 4

Thread: Data binding collection

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    Hi,
    I have a slight issue with binding data using the binding collection. I have a project consisting of a class def. and some client code. Basically the class attaches to and returns records from a database, and binds a field to a simple text box.

    This works fine.

    However when I compile the class into a dll, and create a project reusing the original form, and setting the appropriate references, the data returned is not displayed in the the relevant text box.

    Points to note.
    1. Correct records are definitely returned from the dll
    2. The textbox is named correctly in the add method of the new binding collection
    3. Source is below.

    Any help appreciated.

    Thanks in advance.


    Class:
    ======

    '//=================================================================================================
    '//=================================================================================================
    '//
    '// Tony Hamill
    '// Data Aware Class to scroll through recordset and automtically update records
    '// on the fly.
    '//
    '//==================================================================================================
    '//==================================================================================================



    '//===================================================================================================
    '//===================================================================================================
    '// Module Level Statments
    '//===================================================================================================
    '//===================================================================================================

    Option Explicit

    Private rs As ADODB.Recordset
    Private lb_changed As Boolean
    ' Invoke WithEvents to Confirm Connection was successful
    Private WithEvents cn As ADODB.Connection


    '//===================================================================================================
    '//===================================================================================================
    '// Compiler Constants
    '//===================================================================================================
    '//===================================================================================================


    '//===================================================================================================
    '//===================================================================================================
    '// DLL Imports
    '//===================================================================================================
    '//===================================================================================================


    '//===================================================================================================
    '//===================================================================================================
    '// Constants
    '//===================================================================================================
    '//===================================================================================================

    '//===================================================================================================
    '//===================================================================================================
    '// Enumerated Data Types
    '//===================================================================================================
    '//===================================================================================================



    Private Sub Class_GetDataMember(DataMember As String, Data As Object)

    '//===================================================================================================
    '//===================================================================================================
    '//
    '// The GetDataMember event is available only when an object’s DataSourceBehavior
    '// property is set to vbDataSource or vbOLEDBProvider (for classes only). You can
    '// add code to the GetDataMember event procedure to initialize a data member or to
    '// select from multiple data members within an object.
    '//
    '//===================================================================================================
    '//===================================================================================================

    Set Data = rs
    End Sub

    Private Sub Class_Initialize()
    '//===================================================================================================
    '// Initialise all the relevant connection, recordset values
    '//===================================================================================================

    Dim ls_cn As String
    Dim ls_SQL As String

    ' set no change of text box
    lb_changed = False


    ls_SQL = "Select * from query_status"
    ls_cn = "DSN=Class"

    Set cn = New ADODB.Connection
    Set rs = New ADODB.Recordset

    cn.Open ls_cn
    ' rs.CursorLocation = adUseClient
    rs.Open ls_SQL, ls_cn, adOpenStatic, adLockOptimistic
    MsgBox "Class Initialised"
    MsgBox rs.RecordCount


    End Sub

    Public Sub MoveForward()

    rs.MoveNext
    If rs.EOF Then
    rs.MoveFirst
    End If
    MsgBox rs!querystatus
    End Sub

    Public Sub MoveBack()
    rs.MovePrevious
    If rs.BOF Then
    rs.MoveLast
    End If
    MsgBox rs!querystatus
    End Sub

    Private Sub cn_ConnectComplete(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection)
    ' MsgBox "Connected Succesfully", , "SQL Connection OK"
    End Sub

    Public Sub Check_For_Update(newValue As String)

    '//===========================================================
    '//
    '// Check if text field has changed
    '//
    '//===========================================================

    If lb_changed Then
    rs!querystatus = newValue
    rs.Update
    End If

    lb_changed = False

    End Sub

    Public Sub Text_Changed()
    '//===================================================================================================
    '// Set private member if text box has changed
    '//===================================================================================================

    lb_changed = True
    End Sub



    Client - Form
    ==============

    Private objSource As navigation
    Private objBindingCollection As BindingCollection

    Private Sub Form_Load()

    Set objSource = New navigation
    Set objBindingCollection = New BindingCollection


    ' Assign the source class to the Binding
    ' Collection’s DataSource property.
    Set objBindingCollection.DataSource = objSource
    ' Add a binding to the Collection.
    objBindingCollection.Add txtConsumer, "Text", "queryStatus"
    End Sub

    Private Sub sBtnBack_Click()
    objSource.Check_For_Update (txtConsumer.Text)
    objSource.MoveBack
    End Sub

    Private Sub sBtnForward_Click()
    objSource.Check_For_Update (txtConsumer.Text)
    objSource.MoveForward
    End Sub


    Private Sub txtConsumer_KeyDown(KeyCode As Integer, Shift As Integer)

    ' Ability to use navigation keys
    If KeyCode = 39 Then
    objSource.MoveForward
    ElseIf KeyCode = 37 Then
    objSource.MoveBack
    End If
    End Sub

    Private Sub txtConsumer_KeyPress(KeyAscii As Integer)
    objSource.Text_Changed
    End Sub

  2. #2
    New Member
    Join Date
    Feb 2000
    Location
    Columbus, OH, USA
    Posts
    14
    Have you tried adding you dll class project to you client project and then referencing it. This way you can step into the class code and then you can use the immediate window to see what the current record is. I was just playing around with the example in the MSDN and I got it to work as a dll.
    Hope this helps

  3. #3
    New Member
    Join Date
    Aug 2000
    Posts
    1

    Data Binding

    Try to refresh the data binding properties of your text boxes and other object at run time.

    i.e. txtSample.DataSource = "c:\.....
    txtSample.DataField = "Name"

    I believe this should refresh the connection.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    Soesau,
    I'm not sure what you mean. when using the databinding collection there is no need to set things like datamember, datafield etc. I sthis what you meant?

    Lenin

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