Hi,

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

You need to use a timer.

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

Can you be so kind to post what you coded so far?

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)


        cnCustomers.Open()

        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

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


        Loop

        myData.Close()
        cnCustomers.Close()

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

ReaderTimer.Start

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

Do
    Application.Doevents()
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

ReaderTimer.Stop()

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

can you just use

thread.sleep(5000)

.

or something like that?

@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")
con.open()
dim da as new sqldataadapter("ur sql command",con)
dim dt as new datatable
da.fill(dt)
'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

Regards
M.Waqas Aslam

Hi i got it.
thanx guys !!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.