Click here to Skip to main content
13,143,774 members (31,909 online)
Rate this:
Please Sign up or sign in to vote.
See more:
hey.. is it posible to check if database have new inputed records? and if detected one.. the listview would be reloted? i have tried to create that kind of function but it doesnt work for me, i have the codes below

private sub list_load() 'this is for reloading listview items
dim strsql as string
dim rsload as new adodb.recordset
dim x as integer
dim list as listviewitem

strsql = "select * from customer" 'this is just a sample query

with rsload
.open (strsql,conn)
do while .eof = false
list = lstcustomer.items.add(.fields(0).value)
for x = 1 to 3 step 1
list.subitems(x).text = .fields(x).value
next x
end with
end sub

'this will be the code for the timer-----------------------
dim strsql as string
dim rsload as new adodb.recordset

dim count as integer
dim counthandler as integer


strsql = "select count(*) as total from customer"

with rsload
.open (strsql,conn)
if .eof = false then
count = .fields("total").value
if counthandler = nothing then
counthandler = count + 1
'do nothing
end if
end with

if coumthandler = count then
call list_load 'calls the list_load sub
'no nothing

goto x
the problem is that the code wont work.. my project just hangs. and the purpose of the code is that im trying a lan connection. whenever lan project enters new record, the main project should detect that new record has been added, and if it detects one the listview items should be automatically reloaded again.

it would be easy if i just reload listview items every 1,2,3 seconds using a timer, but i think creating a code for checking if new record has been entered would be good..

please help, advance thanks..:)
Posted 8-Apr-13 18:13pm
Check your Interval of Timer object, because if your timer interval is less than 3000 you will get error however it`s not a good idea for do it work. This solution have a more time complexity and I suggest you change your solution you can use socket programming(server-client) for that purpose.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hello, Buddy

Ya, you are right for when any record or data add in table then automatically alert to we.
But that is not possible bcoz Database work only that store data safely and give our information in requirement in our query.

If you want to detect new record when add in table,
For that you need to reload your table contains through query.

second thing your project was going to hang bcoz you not manage your Forms and Functions in perfect format.

Create one function for getdata from your table
Public funtion GetData()

That function call when you need data of table

For reload your data Create one timer that already you created, But give some timing for hold.
Ex. every five minute or one minite holding timeter

Public Class Form1
    'Configure the timer at form load
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Turn on the timer
        Timer1.Enabled = True
        'Set the interval for each timer "tick"
        Timer1.Interval = 3000      'That time give in miliseconds
    End Sub
    'Actions to perform on each timer tick:
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        MessageBox.Show("This messagebox will popup every 3 seconds!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub
End Class

If any confusing, comment on my answer.

Please improve your coding with divide coding in different function or classes.
For that don't loading on system.

Happy Coding buddy :)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100