Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB6 VB10.0
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..Smile | :)
Posted 8-Apr-13 19:13pm
lalar18428
Comments
AYDIN EBRAHIMI HOMAY at 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

Rate this: bad
good
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!", "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 Smile | :)
  Permalink  
v2

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

  Print Answers RSS
0 Maciej Los 199
1 Sergey Alexandrovich Kryukov 154
2 Sascha Lefévre 120
3 Abhinav S 104
4 Rana Waqas 78
0 Sergey Alexandrovich Kryukov 6,628
1 OriginalGriff 6,298
2 Peter Leow 2,534
3 Maciej Los 2,437
4 Abhinav S 2,378


Advertise | Privacy | Mobile
Web04 | 2.8.150414.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2015
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