Solved

Refresh datagrid using timer event

Posted on 2006-11-02
2
284 Views
Last Modified: 2008-02-26
Hi all,

I am filling my Datagrid like this :

    Private Sub LoadData()
        'Construct data adapter
        SelectCmdString = "select * from SMSQUEUE WHERE Acknowledged=0 order by SMSQueueID"
        da = New SqlDataAdapter(SelectCmdString, conn)
        da.Fill(ds, "SMSQUEUE")
        LabelID.DataBindings.Add("Text", ds, "SMSQUEUE.smsqueueid")
        LabelDate.DataBindings.Add("Text", ds, "SMSQUEUE.createdon")
        LabelDestination.DataBindings.Add("Text", ds, "SMSQUEUE.destination")
        LabelDescription.DataBindings.Add("Text", ds, "SMSQUEUE.description")
        DataGrid1.SetDataBinding(ds, "SMSQUEUE")
        Timer1.Interval = CInt(myInterval) * 1000
        Timer1.Enabled = True

    End Sub

So far so good.

In my timer event I want to refresh the data in the datagrid:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
         LoadData()
End Sub

I have tried setting da= nothing and ds=nothing but that did'nt work.

How can I refresh the data without getting errormessage : This would cause two bindings in the collection to bind to the same property. Parameter name: binding



0
Comment
Question by:JamesBrian
  • 2
2 Comments
 
LVL 34

Expert Comment

by:Sancler
ID: 17858731
It looks as though your dataadapter - da - is declared outside your LoadData sub.  That being so, you don't need to keep reinitialising it every time you want to refresh your data.  Nor, having bound the controls once, do you need to keep re-binding them.  Their contents will update automtically as the datatable's data does.  So just call the LoadData sub once, at the start, and then replace

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
         LoadData()
End Sub

with

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
         da.Fill(ds, "SMSQUEUE")
End Sub

Roger
0
 
LVL 34

Accepted Solution

by:
Sancler earned 250 total points
ID: 17858755
That assumes that your table has a primary key that the dataadapter recognises.  If that's not the case then do this

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
         ds.Tables("SMSQUEUE").Clear
         da.Fill(ds, "SMSQUEUE")
End Sub

Roger
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now