locked
checking before updating records RRS feed

  • Question

  • User1815454672 posted

     HI,

    I am doing multiple updates based on number of textboxes that are retireved by a number in dropdown in gridview based on user selection. I dont wnat tho to update any reords unless all the update statements are true. So I need some help on checking before updating with select I guess. If select is true then i need to update the record(s) if not i display a message with label. The problem is that if 2 textboxes are correct and 3 are not, the updatestatement will execute,but i dont wont that unless all 5 updates are true. thanks.

    code behind 

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim row1 As GridViewRow = GridView1.SelectedRow
            Dim DDL1V As String = CType(row1.FindControl("DDL1"), DropDownList).SelectedItem.Value
            If DDL1V = "1" Then
                If updatedccmembers.Update() = 1 Then
                    Panel0.Visible = "True"
                    Panel1.Visible = "False"
                Else
                    Label1.Text = "INVALID VOUCHER(S). PLEASE TRY AGAIN!"
                    tbv1.Text = ""
                    tbv2.Text = ""
                    tbv3.Text = ""
                    tbv4.Text = ""
                    tbv5.Text = ""
                End If
            End If
            If DDL1V = "2" Then
                If updatedccmembers.Update() = 1 And updatedccmembers1.Update() = 1 Then
                    Panel0.Visible = "True"
                    Panel1.Visible = "False"
                Else
                    Label1.Text = "INVALID VOUCHER(S). PLEASE TRY AGAIN!"
                    tbv1.Text = ""
                    tbv2.Text = ""
                    tbv3.Text = ""
                    tbv4.Text = ""
                    tbv5.Text = ""
                End If
            End If
            If DDL1V = "3" Then
                If updatedccmembers.Update() = 1 And updatedccmembers1.Update() = 1 And updatedccmembers2.Update() = 1 Then
                    Panel0.Visible = "True"
                    Panel1.Visible = "False"
                Else
                    Label1.Text = "INVALID VOUCHER(S). PLEASE TRY AGAIN!"
                    tbv1.Text = ""
                    tbv2.Text = ""
                    tbv3.Text = ""
                    tbv4.Text = ""
                    tbv5.Text = ""
                End If
            End If
            If DDL1V = "4" Then
                If updatedccmembers.Update() = 1 And updatedccmembers1.Update() = 1 And updatedccmembers2.Update() = 1 And updatedccmembers3.Update() = 1 Then
                    Panel0.Visible = "True"
                    Panel1.Visible = "False"
                Else
                    Label1.Text = "INVALID VOUCHER(S). PLEASE TRY AGAIN!"
                    tbv1.Text = ""
                    tbv2.Text = ""
                    tbv3.Text = ""
                    tbv4.Text = ""
                    tbv5.Text = ""
                End If
            End If
            If DDL1V = "5" Then
                If updatedccmembers.Update() = 1 And updatedccmembers1.Update() = 1 And updatedccmembers2.Update() = 1 And updatedccmembers3.Update() = 1 And updatedccmembers4.Update() = 1 Then
                    Panel0.Visible = "True"
                    Panel1.Visible = "False"
                Else
                    Label1.Text = "INVALID VOUCHER(S). PLEASE TRY AGAIN!"
                    tbv1.Text = ""
                    tbv2.Text = ""
                    tbv3.Text = ""
                    tbv4.Text = ""
                    tbv5.Text = ""
                End If
            End If
        End Sub

    asp page

    <asp:SqlDataSource ID="updatedccmembers" runat="server" ConnectionString="<%$ ConnectionStrings:wwadbConnectionString %>"
                            UpdateCommand="UPDATE DCCMembers SET CENAME = @CENAME, CEMAIL = @CEMAIL, CPHONE = @CPHONE WHERE (CID = @CID) AND (CENAME IS Null) AND (CNAME = @CNAME) AND (CSTATUS = '0')">
                            <UpdateParameters>
                                <asp:ControlParameter ControlID="lbname" Name="CENAME" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbem" Name="CEMAIL" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbph" Name="CPHONE" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbv1" Name="CID" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbfn" Name="CNAME" PropertyName="Text" />
                            </UpdateParameters>
                        </asp:SqlDataSource>
                        <asp:SqlDataSource ID="updatedccmembers1" runat="server" ConnectionString="<%$ ConnectionStrings:wwadbConnectionString %>"
                            UpdateCommand="UPDATE DCCMembers SET CENAME = @CENAME, CEMAIL = @CEMAIL, CPHONE = @CPHONE WHERE (CID = @CID) AND (CENAME IS Null) AND (CNAME = @CNAME) AND (CSTATUS = '0')"
                            SelectCommand="SELECT CID, CNAME, CSTATUS FROM DCCMembers WHERE (CID = @CID) AND (CENAME IS Null) AND (CNAME = @CNAME) AND (CSTATUS = 0)">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="tbv2" Name="CID" PropertyName="Text" />
                                <asp:ControlParameter ControlID="lbname" Name="CENAME" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbfn" Name="CNAME" PropertyName="Text" />
                            </SelectParameters>
                            <UpdateParameters>
                                <asp:ControlParameter ControlID="lbname" Name="CENAME" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbem" Name="CEMAIL" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbph" Name="CPHONE" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbv2" Name="CID" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbfn" Name="CNAME" PropertyName="Text" />
                            </UpdateParameters>
                        </asp:SqlDataSource>
                        <asp:SqlDataSource ID="updatedccmembers2" runat="server" ConnectionString="<%$ ConnectionStrings:wwadbConnectionString %>"
                            UpdateCommand="UPDATE DCCMembers SET CENAME = @CENAME, CEMAIL = @CEMAIL, CPHONE = @CPHONE WHERE (CID = @CID) AND (CENAME IS Null) AND (CNAME = @CNAME) AND (CSTATUS = '0')">
                            <UpdateParameters>
                                <asp:ControlParameter ControlID="lbname" Name="CENAME" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbem" Name="CEMAIL" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbph" Name="CPHONE" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbv3" Name="CID" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbfn" Name="CNAME" PropertyName="Text" />
                            </UpdateParameters>
                        </asp:SqlDataSource>
                        <asp:SqlDataSource ID="updatedccmembers3" runat="server" ConnectionString="<%$ ConnectionStrings:wwadbConnectionString %>"
                            UpdateCommand="UPDATE DCCMembers SET CENAME = @CENAME, CEMAIL = @CEMAIL, CPHONE = @CPHONE WHERE (CID = @CID) AND (CENAME IS Null) AND (CNAME = @CNAME) AND (CSTATUS = '0')">
                            <UpdateParameters>
                                <asp:ControlParameter ControlID="lbname" Name="CENAME" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbem" Name="CEMAIL" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbph" Name="CPHONE" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbv4" Name="CID" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbfn" Name="CNAME" PropertyName="Text" />
                            </UpdateParameters>
                        </asp:SqlDataSource>
                        <asp:SqlDataSource ID="updatedccmembers4" runat="server" ConnectionString="<%$ ConnectionStrings:wwadbConnectionString %>"
                            UpdateCommand="UPDATE DCCMembers SET CENAME = @CENAME, CEMAIL = @CEMAIL, CPHONE = @CPHONE WHERE (CID = @CID) AND (CENAME IS Null) AND (CNAME = @CNAME) AND (CSTATUS = '0')">
                            <UpdateParameters>
                                <asp:ControlParameter ControlID="lbname" Name="CENAME" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbem" Name="CEMAIL" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbph" Name="CPHONE" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbv5" Name="CID" PropertyName="Text" />
                                <asp:ControlParameter ControlID="tbfn" Name="CNAME" PropertyName="Text" />
                            </UpdateParameters>
                        </asp:SqlDataSource>

    Thursday, December 16, 2010 1:28 AM

Answers

  • User1992938117 posted

    You can use SQL Query as:

    select * from myTable where ID='123'
    if @@rowcount = 0
    insert into myTable (Col1, Col2) values (@col1, @col2)
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 16, 2010 4:45 AM