I want a database change to be reflected in web forms page without polling the database

Manoj Gokhale 0 Reputation points
2023-06-07T02:04:37.62+00:00

Hello

I have a web page whose records are based on a database table. If there is a change in the database table I wish to get it reflected on my front end web form in vb.net code behind.

I do not want my web page to be refreshed by a user interaction like a refresh button

Is there a way by which my database can call a frontend vb.net procedure or something like that?

Please help me

regards

Manoj gokhale

Developer technologies | ASP.NET | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. QiYou-MSFT 4,326 Reputation points Microsoft External Staff
    2023-06-07T07:49:49+00:00

    Hi @Manoj Gokhale

    You can use asp:ScriptManager, asp:UpdatePanel, and asp:Timer to achieve automatic partially refresh.

    Since asp:ScriptManager, asp:UpdatePanel can implement partial scripting functions. At the same time<asp:timer> can realize the function of performing an operation at a regular time. This enables the ability to partially refresh data (without requiring the user to submit a request).

    Code:

    <body>
        <form id="form1" runat="server">
            <b>Test</b>
           <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <asp:UpdatePanel ID="updPanel" runat="server">
                          <ContentTemplate>
                               <asp:Timer ID="timerTest" runat="server" Interval="2000" OnTick="Timer1_Tick">
                              </asp:Timer>
                              <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ appSettings:ConnStr %>" SelectCommand="select Name,Age from dbo.Test">
                                  </asp:SqlDataSource>
                                  <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"  AutoGenerateColumns="False">
                <Columns>
                    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                    <asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
                </Columns>
            </asp:GridView>
                          </ContentTemplate>
                      </asp:UpdatePanel>
        </form>
    </body>
    
    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
            GridView1.DataBind()
        End Sub
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        End Sub
    

    Output:

    TestSQL

    Best regards,

    Qi You


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. SurferOnWww 4,706 Reputation points
    2023-06-11T01:24:46.46+00:00

    If your database is the SQL Server you will use the query notifications which allow web application to be notified when data has changed.

    Query Notifications in SQL Server

    By using the SignalR the web application can broadcast the updated data to the connected clients.

    Sample is shown in the following article. Sorry it is written in Japanese.

    [SignalR and SqlDependency]

    http://surferonwww.info/BlogEngine/post/2021/12/26/signalr-and-sqldependency-on-aspnet-web-application.aspx


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.