ARTICLE

How to Bind Timer,Database,Label and DataGridview in ADO.NET

Posted by Munesh Sharma Articles | ADO.NET in VB.NET April 29, 2011
In this article, we will learning how to bind Timer, Database and Label.
Download Files:
 
Reader Level:

Timer Control:

A timer is a non-spatial object that uses recurring lapses of time in a computer or in your application. To work, every lapse of period, the control sends a message to the operating system. The message is something to the effect of "I have counted the number of lapses you asked me to count".

Label Control:

Label is control in .NET, which is used represent some text in window and web application. but it is use full to create the timer and hiding text.

Binding Timer, Database, DataGridview and Label:

There are various steps to bind controls in Database:

  • Step first, to design Database:

    data-base-design.gif

  • Step second, to design window forms:

    Win-design.gif

  • Step third, Write these code

    Connection Coding:

    Imports System.Data.OleDb
    Module
    Module1
        Public constringAs OleDbConnection =New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=D:\my_db7.accdb")

    End
    Module

    Coding for Form:

    Imports System.Data.OleDb  
    Public
    Class Form1
        Dim Ds As DataSet
        Dim Da As OleDbDataAdapter
        Dim Sql1 As String
       
        Private Sub Timer1_Tick(ByVal senderAs System.Object, ByVal e As System.EventArgs)Handles Timer1.Tick
            Label3.Text += 1
            If Label3.Text = 60Then
                Label2.Text += 1
                Label3.Text = "0"
            ElseIf Label2.Text ="1" Then
                Label4.Text = "Data base First table"
      
                constring.Open()
                Ds = New DataSet
                Sql1 = "select * from  companyp "
                Da = New OleDbDataAdapter(Sql1, constring)
                Da.Fill(Ds, "companyp")
                DataGridView1.DataSource = Ds.Tables(0)
                constring.Close()      
            ElseIf Label2.Text ="2" Then
                Label4.Text = ""
                Label4.Text = "Database Second table"
     
                constring.Open()
                Ds = New DataSet
                Sql1 = "select * from Localp "
                Da = New OleDbDataAdapter(Sql1, constring)
                Ds.Reset()
                Da.Fill(Ds, "Localp")
                DataGridView1.DataSource = Ds.Tables(0)
                constring.Close() 
            ElseIf Label2.Text ="3" Then
                Label4.Text = ""
                Label4.Text = "Database Third table"
                constring.Open()
                Ds = New DataSet
                Sql1 = "select * from info1 "
                Da = New OleDbDataAdapter(Sql1, constring)
                Ds.Reset()
                Da.Fill(Ds, "info1")
                DataGridView1.DataSource = Ds.Tables(0)
                constring.Close() 
            ElseIf Label2.Text = 60Then
                Label1.Text += 1
                Label2.Text = "0"
                Label3.Text = "0"
                
    End
    If          
    End
    Sub
     
        Private Sub Button1_Click(ByVal senderAs System.Object, ByVal e As System.EventArgs)Handles Button1.Click
            Timer1.Interval = "100"
            Timer1.Enabled = True       
        End Sub
     
        Private Sub Button2_Click(ByVal senderAs System.Object, ByVal e As System.EventArgs)Handles Button2.Click
            Timer1.Enabled = False
      
        End Sub
     
        Private Sub Form1_Load(ByVal senderAs System.Object, ByVal e As System.EventArgs)Handles MyBase.Load 
        End Sub
     
        Private Sub Button3_Click(ByVal senderAs System.Object, ByVal e As System.EventArgs)Handles Button3.Click       
           Timer1.Enabled = False
            Label3.Text = "0"
            Label2.Text = "0"
            Label1.Text = "0"
           
    End
    Sub

    End
    Class   

Output:

                        outputd.gif

                        outputd2.gif

                        outputd3.gif

                        outputd4.gif

 

 
 


Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor