Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
.movenext
loop
.close
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

x:

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
else
'do nothing
end if
endif
.close
end with

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

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
Comments
Aydin Homay 9-Apr-13 1:22am    
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

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


VB
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!", "www.interloper.nl", 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 :)
HTML

 
Share this answer
 
v2

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