locked
Is it possible to set updatepanel to update after SQL insert command RRS feed

  • Question

  • User615288127 posted

    I'm using Visual Web Developer 2010 Express with SQL Server 2008 Express, VB.

    I would like to know if it is possible to issue a command that would cause an updatepanel to update after a SQL Insert command has been executed.  If so, how can this be accomplished.  Can someone provide an example of how to do this?

    Thanks!

    Tuesday, August 11, 2015 8:23 AM

Answers

  • User615288127 posted

    Refer to AJAX solution for "Need help with updatepanel"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 20, 2015 8:45 AM

All replies

  • User37182867 posted

    Need a little more description here. Where is the SQL being run from? Stored Proc on the database server? From code on the code behind on the page?

    Tuesday, August 11, 2015 8:53 AM
  • User615288127 posted

    Hi deadtroll,

    A snippet of my VB code is below:

            querystring = "SELECT * FROM [TMPPRTS] ORDER BY [TMPPRTNO]"     '4
            R = 0
            sqlConnection.Open()
            command = New SqlCommand(querystring, sqlConnection)
            reader = command.ExecuteReader()
            While reader.Read()
                Prt1 = reader(0).ToString
                idList.Add(Prt1.ToString())
                Prt2 = reader(1).ToString
                idList.Add(Prt2.ToString())
                Prt3 = reader(2).ToString
                idList.Add(Prt3.ToString())
                Prt4 = reader(3).ToString
                idList.Add(Prt4.ToString())
                X = X + 4
                R = R + 1
            End While
            sqlConnection.Close()
    
            Z = 0
            For X = 1 To R Step 1
                querystring = "INSERT INTO [TMPPRTS] ([TMPPRTNO], [RELPRTNO], [USERNAME], [CREATETIME]) VALUES("
                For Y = 0 To 3 Step 1
                    querystring = querystring & "'" & idList(Z) & "'"
                    If Y <> 3 Then querystring = querystring & ", "
                    If Y = 3 Then querystring = querystring & ")"
                    Z = Z + 1
                Next
    
                Using conn As New OleDbConnection(ConnString)
                    Using cmd1 As New OleDbCommand(querystring, conn)
                        cmd1.CommandType = CommandType.Text
                        conn.Open()
                        cmd1.ExecuteNonQuery()  'TMPPRTS
                    End Using
                    conn.Close()
                End Using
                TextBox13.Text = X
            Next

    ASP portion:

    <asp:UpdatePanel ID="UpdatePanel13" runat="server">
            <ContentTemplate>
                <asp:Label ID="Label13" runat="server" Text="TMPPRTS" Width="200px"></asp:Label>
                &nbsp;
                <asp:TextBox ID="TextBox13" runat="server"></asp:TextBox>
            </ContentTemplate>
        </asp:UpdatePanel>

    Somewhere in the above loop I would like TextBox13 to show the updated value of the number of Inserts.  The full program has several tables transferred to Access and for some reason the textboxes don't update until after all table Inserts have been completed.  This has resulted in the user not knowing if anything is actually happening or not.

    Thanks!

    Tuesday, August 11, 2015 9:04 AM
  • User37182867 posted

    You might be able to do something with an ajax call and some aynch programming.

    But I know of no straight forward way to do what you are wanting. 

    I however would just resolve this with a loading indicator from your update panel

    http://stackoverflow.com/questions/7704171/asp-net-display-loading-message-while-update-panel-is-updating

    check this link to see how you might implement it.

    Thursday, August 13, 2015 12:16 PM
  • User615288127 posted

    Thanks DeadTroll,

    I've looked over the link and tried a few things but haven't figured it out yet.  For a newbie this is some of the most confusing stuff I've come across so far!

    Does anyone else have any suggestions?

    Thanks!

    Tuesday, August 18, 2015 11:19 AM
  • User615288127 posted

    Refer to AJAX solution for "Need help with updatepanel"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 20, 2015 8:45 AM