I want the sql dependancy on gridview to be changed displaying all data rows help please my code is
Code:
public void SendNotifications() { string message = string.Empty; string conStr = ConfigurationManager.ConnectionStrings["TestDB"].ConnectionString; using (SqlConnection connection = new SqlConnection(conStr)) { string query = "SELECT [Message] FROM [dbo].[tb]"; using (SqlCommand command = new SqlCommand(query, connection)) { command.Notification = null; SqlDependency dependency = new SqlDependency(command); dependency.OnChange += new OnChangeEventHandler(dependency_OnChange); connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { message = reader.GetString(0); } } } } NotificationsHub nHub = new NotificationsHub(); nHub.NotifyAllClients(message); } private void dependency_OnChange(object sender, SqlNotificationEventArgs e) { if (e.Type == SqlNotificationType.Change) { SendNotifications(); } } } } <script> $(function () { var notify = $.connection.notificationsHub; notify.client.displayNotification = function (msg) { $("#newData").html(msg); }; $.connection.hub.start(); }); </script> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView id="newData" runat="server" AutoGenerateColumns="False"> </asp:GridView>
Comment