Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
i hv a DatagridView in Windows Based project, in which data need to be populated from datbase after every 5 minute or as soon as new data is populated in Database tables
Posted
Comments
Neetesh Agarwal 6-Apr-13 5:16am    
Use Timer.......................

C#
public Form
{
    timer1.Interval = (1000) * (300);             // Timer will tick every 300 seconds
    timer1.Enabled = true;                       // Enable the timer
    timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
     function(); call function here
}
 
Share this answer
 
v2
Hi.. User Ajax Timer do the same.. You can use UpdatePanel to avoid page refresh.
Ex:
Html part..
ASP.NET
<asp:scriptmanager runat="server" id="ScriptManager1" xmlns:asp="#unknown" />
        <asp:timer id="Timer1" runat="server" interval="50000" ontick="Timer1_Tick" xmlns:asp="#unknown">
        </asp:timer>
        <asp:updatepanel id="UpdatePanel1" runat="server" xmlns:asp="#unknown">
            <triggers>
                <asp:asyncpostbacktrigger controlid="Timer1" eventname="Tick" />
            </triggers>
            <contenttemplate>
                
              // place your gridview here to avoid page refresh for regular interval of 5 minutes

            </contenttemplate>
        </asp:updatepanel>

Interval="50000" is equals to 5 minutes..

Code behind..
C#
protected void Timer1_Tick(object sender, EventArgs e)
    {
        //write code to load and bind data
    }
 
Share this answer
 
Comments
Neetesh Agarwal 6-Apr-13 5:55am    
But How in Window Application?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900