Solved

Refresh datagrid using timer event

Posted on 2006-11-02
2
292 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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