Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Cancel an "Update" or "Insert"

$
0
0

Ok, I have a ListView and when someone gets an error trying to update or insert a record, the information from the fields disappears and the database gets updated with NULLs. All I'm trying to do is do nothing. just stop what they are doing and reset the fields as if they cancelled the update or insert. I thought that if I just bypassed the SQL calls all-together that it would reset, but no.

Here's the EditItemTemplate code:

<EditItemTemplate><tr align="center"
                            style="background-color:#B5C7DE; color: #000000; font-family: Calibri; font-weight: bold;"><td><asp:ImageButton ID="UpdateButton" runat="server" CommandName="Update"
                                    Height="24" ImageUrl="Images/Save-icon.png" ToolTip="Update"
                                    ValidationGroup="ValidationGroup1" Width="24" /><asp:ImageButton ID="CancelButton" runat="server" CommandName="Cancel"
                                    ImageUrl="Images/RTT blue-arrow-undo-icon.png" ToolTip="Cancel" /></td><td><asp:TextBox ID="IGBNumTextBox" runat="server" AutoPostBack="true"
                                    CausesValidation="True" MaxLength="6"
                                    OnTextChanged="IGBNumEditTextBox_TextChanged" style="text-align:center"
                                    Text='<%# Bind("IGBNum") %>' Wrap="False" /><asp:CompareValidator ID="CompareValidator1" runat="server"
                                    ControlToValidate="IGBNumTextBox"
                                    ErrorMessage="IGB number must be greater than 500000"
                                    Operator="GreaterThanEqual" Text="*" ValidationGroup="ValidationGroup1"
                                    ValueToCompare="500000"></asp:CompareValidator></td><td><asp:TextBox ID="ManufacturerTextBox" runat="server" AutoPostBack="true"
                                    MaxLength="9" Text='<%# Bind("Manufacturer") %>' Enabled="False" /></td><td><asp:TextBox ID="ModelTextBox" runat="server" MaxLength="3"
                                    Text='<%# Bind("Model") %>' Enabled="False" /></td><td><asp:TextBox ID="SerialNumTextBox" runat="server"
                                    Text='<%# Bind("SerialNum") %>' Enabled="False" MaxLength="20"/></td></tr></EditItemTemplate>

and the code behind:

            If Command = "Update" Then
                Dim Duplicate As Boolean
                Dim tbIGBNum As TextBox = CType(ListView1.EditItem.FindControl("IGBNumTextBox"), TextBox)

                If tbIGBNum.Text = "" Then
                    MsgBox("IGB Number can not be blank")
                End If
                If tbIGBNum.Text.Length < 6 Then
                    MsgBox("IGB Number can not be under 6 digits")
                End If
                If Not IsNumeric(tbIGBNum.Text) Then
                    MsgBox("IGB Number Must be Numeric")
                End If

                If tbIGBNum.Text <> "" Or tbIGBNum.Text.Length = 6 Or IsNumeric(tbIGBNum.Text) Then
                    Using conn As New SqlConnection("Data Source=SLOTS;Initial Catalog=RTT_DEV;Integrated Security=True")
                        Using cmd As New SqlCommand("SELECT TransIndex FROM DevicesTransported WHERE TerminalOperatorNum = @TerminalOperatorNum AND TransID = @TransID AND IGBNum = @IGBNum", conn)
                            cmd.Parameters.AddWithValue("TerminalOperatorNum", tbTerminalOperator.Text)
                            cmd.Parameters.AddWithValue("TransID", _TransID)
                            cmd.Parameters.AddWithValue("IGBNum", tbIGBNum.Text)
                            conn.Open()
                            Dim Reader = cmd.ExecuteReader
                            If Reader.HasRows Then
                                While Reader.Read
                                    Duplicate = True
                                End While
                            End If
                            Reader.Close()
                        End Using
                    End Using

                    If Duplicate Then
                        MsgBox("This IGB Number already exist on the list.")
                    Else
                        Using conn As New SqlConnection("Data Source=SLOTS;Initial Catalog=RTT_DEV;Integrated Security=True")
                            Using cmd As New SqlCommand("UPDATE DevicesTransported SET TerminalOperatorNum = @TerminalOperatorNum WHERE (TransID = @TransID)", conn)
                                cmd.Parameters.AddWithValue("TerminalOperatorNum", tbTerminalOperator.Text)
                                cmd.Parameters.AddWithValue("TransID", _TransID)
                                conn.Open()
                                Dim Reader = cmd.ExecuteReader
                                If Reader.HasRows Then
                                    While Reader.Read
                                    End While
                                End If
                                Reader.Close()
                            End Using
                        End Using

                        SqlDataSource1.UpdateParameters.Item("TransID").DefaultValue = _TransID
                        SqlDataSource1.UpdateParameters.Item("TerminalOperatorNum").DefaultValue = tbTerminalOperator.Text
                        SqlDataSource1.DataBind()

                        SqlDataSource1.SelectParameters("TerminalOperatorNum").DefaultValue = tbTerminalOperator.Text
                        SqlDataSource1.SelectParameters("TransID").DefaultValue = _TransID

                    End If
                End If
            End If




Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>