如何在新项目添加到数据库时向用户发送通知。 [英] How to sent a notification to user when a new item added in to the database.

查看:68
本文介绍了如何在新项目添加到数据库时向用户发送通知。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在数据库中添加单词时,我有一个聊天应用程序,通知应该告诉我在数据库中添加了一个新项目,并且应该在有人向特定数据库添加任何内容的同时发生。它应该是使用c#和.net。



其实我需要的是我需要一种技术来执行以找到在数据库中添加的新项目它应该当有人在我的数据库中添加一个项目的同时发生。



我的表格会是这样的



来自|到|文字

xx | yy | hellow

zz | uu | Hai



如果xx为yy添加了文本hellow



yy应该得到xx添加的文本同时xx添加到数据库。

I have an application for chatting when the user add a word in the database a notification should come to me that a new item is added in the database and it should happen at the sametime when someone have added anything to a particular database. It should be by using c# and .net .

Actually what i need is i need a technique to execute to find the new item which added in the database and it should occur at the same time when someone added an item in to my database.

My Table will be like this

From | To | Text
xx | yy | hellow
zz | uu | Hai

if xx added a text hellow to yy

yy should get the text which xx have added to the database at the same time xx adding.

推荐答案

您可以在插入代码后使用它:

You can use this after your insertion code:
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Record Inserted Successfully')", true);


您将在你的桌子上创建触发器。当任何新记录插入该表时,触发器会自动触发,在触发器内部,您可以获取插入的值并使用此值执行任何操作。

请阅读以下触发器相关文章

触发器 - Sql Server [ ^ ]
You will create trigger on your table. When any new record is inserted to that table then the trigger is fired automatically and inside that trigger you can get the value which is inserted and do anything with this value.
Please read the following trigger related article
Triggers -- Sql Server[^]


当你标记您对 Javascrip 的问题,我假设您想制作一个Web应用程序。好吧,它的一部分取决于你使用的框架(WebForms,Web Pages,MVC ......),但关键是你如何能够通知一个无状态的客户端(运行在一个html / javascript应用程序部分)浏览器就是这样一个客户端。

如果你能确保所有客户端都运行支持HTML5(Websockets)的浏览器,你就可以采用这种方法: HTML5与Websockets,jQuery和Spike-Engine的实时聊天 [ ^ ]。如果没有,你必须考虑从客户端进行一些自动轮询(这不是即时的,但可以非常快 - 关于你的网络瓶颈)。这个轮询可以通过ajax调用完成。

这里有一个库,可以从你的应用程序的角度透明地处理它: SignalR [ ^ ]
As you tagged your question with Javascrip, I assume you want to make a web application. Well, part of it will depend on the framework you use (WebForms, Web Pages, MVC...), but the key point is how you are able to notify a state-less client (a html/javascript application part running in a browser is such a client).
If you can ensure, that all client run HTML5 (Websockets) enabled browser, you can take this approach: HTML5 Real-Time Chat with Websockets, jQuery, and Spike-Engine[^]. If not, you have to consider some automatic polling from client side (this won't be instantaneous, but can be quite quick - with regards to your network bottlenecks). This polling can be simply done with an ajax call.
Here you have a library that can handle this transparently from your application's point of view: SignalR[^]


这篇关于如何在新项目添加到数据库时向用户发送通知。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆