?
Solved

Refresh datagrid using timer event

Posted on 2006-11-02
2
Medium Priority
?
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

765 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