Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
iam working on asp.net4 web site
i need to do some thing
when row add in specific table
user open the web site have alarm that row has been added to table
how can i do that
Posted

There are any number of ways to accomplish this. How do you indicate a new record has been added to the database? One method is to have a date/time column in the record set to the date/time it was inserted. You would also have a date/time stored for the client, perhaps as a cookie, that indicates the last time data was accessed by them. If any records have been added after the date/time on the client, display your message.
 
Share this answer
 
Comments
[no name] 4-Oct-11 13:27pm    
i want the user to be notify when he is online
mean the user is now logged in
& then row inserted in the table so an notify appear to user evrery time row is add
[no name] 4-Oct-11 18:40pm    
You will need to poll the data occasionally to check for updates. A web page is not a push container. Remember the server has no way of knowing if the page is still active in the users browser or if they've gone to lunch. Also, you have take into consideration that the user may be on a mobile device and you don't want to hog their bandwidth and data plan minutes.
if your database is SQL Server then you might to look at SQL Notification Services. But a simple approach would be to, use a trigger to capture the changes in that table and queue the notification in another table.

Then when the user logs in to the website, you check for 'previously not shown' notifications and display them.

if you need it realtime, then u would need to start looking at push notification service like pubnub.

Thx

Sazzad

[EDIT:]

actually it depends on which situation u r using it. If it's a corporate db and u have many apps using it, i.e. no single layer of data access, then u would either have to resort to a single SP to do the insert (where u would include the audit log insert) or in trigger. Now if you are not inserting a millions of rows in a single batch, trigger performance is not that bad. Also you are really worried with perf, you might want to use async triggers. (yes there is a way to implement this in sql server). But overall if u want to keep this audit log in a table, you end up having two inserts or extra columns like u said.



I assume the column way is easier with a default value of (GETDATE()). Then everytime u do an insert it will have the latest datetime in it. U keep a cookie in users browser or somehow persist that info in a DB table or profile somewhere and compare against that date. Then everytime now and then when u render u display the new records by doing a date compare query. But other than just the datetime of new rows, if u need more information like which pc/user etc it was added from then u might end up having an audit log table.

 
Share this answer
 
v3
Comments
[no name] 4-Oct-11 12:06pm    
A trigger has unnecessary overhead and SQL Notification Services requires and open connection, which is not made until the page is requested. Neither will push services will work with an on-demand web application. Not a good solutions.
[no name] 4-Oct-11 13:27pm    
i want the user to be notify when he is online
mean the user is now logged in
& then row inserted in the table so an notify appear to user evrery time row is add

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