Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Databound controls not updating when datasource updates
Message
De
23/03/2006 09:58:47
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
22/03/2006 17:58:11
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
VB.NET 1.1
Database:
MS SQL Server
Divers
Thread ID:
01106656
Message ID:
01106986
Vues:
22
Hey Bonnie,
I simplified my problem down as must as possible (I think):
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RefreshData()
        RetireeView.Table = gRetireeDS.Tables("Retiree")
        Call BindFields()
    End Sub

    Private Sub RefreshData()
        gRetireeDS = gfncRetiree_Load()
    End Sub

    Private Sub BindFields()
        txtFirstName.DataBindings.Add(New Binding("text", RetireeView, "FirstName"))
        txtLastName.DataBindings.Add(New Binding("text", RetireeView, "LastName"))
        txtLastUpdated.DataBindings.Add(New Binding("text", RetireeView, "LastUpdated"))
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call RefreshData()
    End Sub

    Public Function gfncRetiree_Load() As DataSet
        Dim Retiree As New DataSet
        Dim myDataAdapter As New SqlDataAdapter
        myDataAdapter.SelectCommand = New SqlCommand
        myDataAdapter.SelectCommand.Connection = Conn1
        myDataAdapter.SelectCommand.CommandText = "SELECT * FROM Retiree ORDER BY Counter"
        myDataAdapter.SelectCommand.CommandType = CommandType.Text

        Try
            Conn1.Open()
            Retiree.Clear()
            myDataAdapter.Fill(Retiree, "Retiree")
        Catch
            MsgBox(Err.Number & " : " & Err.Description)
        Finally
            Conn1.Close()
        End Try
        gfncRetiree_Load = Retiree
        myDataAdapter.Dispose()
        Retiree.Dispose()
    End Function 'gfncRetiree_Load
Now, to actually make this work, I change BindFields() to clear the databindings, set RetireeView.Table = gRetireeDS.Tables("Retiree"), and rebind the fields. I then have to call BindFields() in RefreshData(). That seems like a lot of hoops to jump through.

Thanks for any guidance! I finally have some real time to devote to a project instead of finding the quickest way to get something done. I would really like to start learning some best practices.
Very fitting: http://xkcd.com/386/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform