I want to connect my vbform having two textboxes with a button.Each textbox will display some value from connected database in a loop (with interval of 5 sec for each value) on pressing button once.

Front end :- Vb.net
Database : MS Access

Pls help me

5 Years
Discussion Span
Last Post by vb.netfreak

but i need coding from begining of a sub as i am not able to iterate my database values.


This is my code

Public Const cnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=C:\customer.mdb"

        ssql = "SELECT c_name, address FROM detail"

        Dim cnCustomers As OleDbConnection
        Dim sqlCmd As OleDbCommand = New OleDbCommand(ssql)
        Dim myData As OleDbDataReader

        cnCustomers = New OleDbConnection(cnString)


        sqlCmd.Connection = cnCustomers

        myData = sqlCmd.ExecuteReader

        Dim strValue As String

        Do While myData.Read

            strValue = IIf(myData.IsDBNull(0), "", myData.GetValue(0))
            '  CButton27.Text = strValue

            For shtCntr = 1 To myData.FieldCount() - 1

                If myData.IsDBNull(shtCntr) Then

                    CButton27.Text = strValue
                    CButton28.Text = (myData.GetString(shtCntr))
                End If
            Next shtCntr



but not able to display value after particular interval


Before you start reading data you'll need a timer

Dim WithWEvents ReaderTimer as Timer = new Timer

In order to define a withevents timer, you must do so on the class level.

Then, in this sub, initialize it to 5 seconds interval.

ReaderTimer.Interval=5000 ' In thousands of seconds

And Start the timer


Also, you'll need a interval read permission like

Dim CanRead as Boolean = Flase

to be defined in this sub.

Then, before the Loop sentence you should add

Loop Until CanRead
CanRead = False

This will put the application in a wait state until the timer is fired.
Before the myData.Close() you should stop the timer with


In order to catch the Tick event from the ReaderTimer you should create a new sub

Sub RederTimer_Tic(myObject As Object, _
      ByVal myEventArgs As EventArgs) Handles ReaderTimer.Tick
    CanRead = True
End Sub

None of this code has been tested, but I hope this helps


@lolafuertes:- i am not able to get you please elaborate.
@phoenix911 :- the whole application get into sleep mode

i want when user press a button1, data load onto my button2 text from database and data automatically get refresh after 30 sec.


On your first post, I understood to ahow every five seconds to show a row.
On your last one, are you saying every 30 the hole database info?

Please elaborate

What is unclear for you?

I think I described, every sentence and the exact place to put each, all what you need to do modify the piece of code you wrote here.

Please le us know


hello !
i think this will helps you , i dont know much about dealing with access so here is code for mssql to perform same function which u want

dim con as new sqlconnection("connection string")
dim da as new sqldataadapter("ur sql command",con)
dim dt as new datatable
'now take a bindingsource control
bindingsource1.datasource= dt
textbox1.DataBindings .Add ("text",bindingsource1,"Field name",false)
textbox2.DataBindings .Add ("text",bindingsource1,"Field name",false)

after this place a timer control and set interval according to your requirement .1000 = 1 sec
now place this code on timers tick event before this , you have to declare a variable name i on the top as a global variable datatype int

i = i+1
bindingsource1.position = bindingsource.position + 1

this code will change the position of the bindingsource after each tick , and the values of your textboxes will also changed .

Hope this will helps you

M.Waqas Aslam

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.