I want the sql dependancy on gridview to be changed displaying all data rows help ple

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abelgebray
    New Member
    • Jan 2016
    • 1

    I want the sql dependancy on gridview to be changed displaying all data rows help ple

    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>
    Last edited by Rabbit; Jan 25 '16, 05:09 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    What issues are you having with your current code. What is it not doing that you need it to do?

    Comment

    Working...