locked
asp.net 2.0 for dummies RRS feed

  • Question

  • User609686767 posted

    I was trying this sample, but it seems it does not update nor delete the current record. I don't understand really how the parameters work and how does it get the value when I didn't supply anything. When I click the button, it just seem to refresh the page, but the record is left unchanged. What is wrong with the query? Thanks

      

    <%@ Page Language="vb" AutoEventWireup="true" Inherits="ClassyClassifieds.EditAd" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        
        Private Sub DetailsView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewCommandEventArgs) Handles DetailsView1.ItemCommand
    
        End Sub
    
        Private Sub DetailsView1_ItemDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewDeletedEventArgs) Handles DetailsView1.ItemDeleted
                
        End Sub
    
        Private Sub DetailsView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) Handles DetailsView1.ItemUpdated
    
        End Sub
          
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
           
        End Sub
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <% Response.Write(Request.QueryString("AdNum"))%>
        </div>
       
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:classydbConnectionString %>" 
            ProviderName="<%$ ConnectionStrings:classydbConnectionString.ProviderName %>" 
            
            ConflictDetection="CompareAllValues" 
            SelectCommand="SELECT * FROM [Ads] WHERE (AdNum=?)" 
            
            DeleteCommand="DELETE FROM [Ads] WHERE [AdNum] = ? AND [Title] = ? 
            AND [Category] = ? AND [Description] = ? AND [Price] = ? AND [Phone] = ? 
            AND [Email] = ? AND [State] = ? AND [UserPassword] = ?" 
                   
            UpdateCommand="UPDATE [Ads] SET [Title] = ?, [Category] = ?, [Description] = ?, 
            [Price] = ?, [Phone] = ?, [Email] = ?, [State] = ?, [UserPassword] = ? 
            WHERE [AdNum] = ? AND [Title] = ? AND [Category] = ? AND [Description] = ? 
            AND [Price] = ? AND [Phone] = ? AND [Email] = ? AND [State] = ? AND [UserPassword] = ?">
            
            
            <%-- from DELETE 
              --%>
            
            
            <SelectParameters>
                <asp:QueryStringParameter Name="AdNum"  QueryStringField="AdNum" Type="Int32"/>
            </SelectParameters>
            
            <DeleteParameters>
                <asp:Parameter Name="oAdNum" Type="Int32" />
              <%--  <asp:Parameter Name="Title" Type="String" />
                <asp:Parameter Name="Category" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="Price" Type="Decimal" />
                <asp:Parameter Name="Phone" Type="String" />
                <asp:Parameter Name="Email" Type="String" />
                <asp:Parameter Name="State" Type="String" />
                <asp:Parameter Name="UserPassword" Type="String" /> --%>
            </DeleteParameters>
            
            <UpdateParameters>
                <asp:Parameter Name="Title" Type="String" />
                <asp:Parameter Name="Category" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="Price" Type="Decimal" />
                <asp:Parameter Name="Phone" Type="String" />
                <asp:Parameter Name="Email" Type="String" />
                <asp:Parameter Name="State" Type="String" />
                <asp:Parameter Name="UserPassword" Type="String" />
                <%--the WHERE parameters --%>
                <asp:Parameter Name="oAdNum" Type="Int32" />
                <asp:Parameter Name="oTitle" Type="String" />
                <asp:Parameter Name="oCategory" Type="String" />
                <asp:Parameter Name="oDescription" Type="String" />
                <asp:Parameter Name="oPrice" Type="Decimal" />
                <asp:Parameter Name="oPhone" Type="String" />
                <asp:Parameter Name="oEmail" Type="String" />
                <asp:Parameter Name="oState" Type="String" />
                <asp:Parameter Name="oUserPassword" Type="String" />
            </UpdateParameters>
            
        </asp:SqlDataSource>
        <asp:DetailsView ID="DetailsView1" runat="server" Height="20px" Width="100%"
        autogeneraterows="False" DataSourceID="SqlDataSource1"
        DataKeyNames="AdNum"
        OnItemDeleted="DetailsView1_ItemDeleted"
        OnItemUpdated="DetailsView1_ItemUpdated" 
        OnItemCommand="DetailsView1_ItemCommand">
        
            <Fields>
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="Category" HeaderText="Category" 
                    SortExpression="Category" />
                <asp:BoundField DataField="Description" HeaderText="Description" 
                    SortExpression="Description" />
                <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
                <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
                <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
                <asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
                <asp:BoundField DataField="UserPassword" HeaderText="User Password" 
                    SortExpression="UserPassword" />
                    
                <asp:CommandField ButtonType="Button" ShowDeleteButton="True" 
                    ShowEditButton="True" />
                    
            </Fields>
        </asp:DetailsView>
        </form>
    </body>
    </html>
    
     

     

     

    Wednesday, April 8, 2009 6:13 AM

Answers

  • User-1199946673 posted

    If you set ConfictDetection="CompareAllValues", you must also specify the OldValuesParameterFormatString property, so that .NET can recognize the parameters. In your example, it is:

    OldValuesParameterFormatString="o{0}"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 8, 2009 7:42 AM

All replies

  • User-1199946673 posted

    If you set ConfictDetection="CompareAllValues", you must also specify the OldValuesParameterFormatString property, so that .NET can recognize the parameters. In your example, it is:

    OldValuesParameterFormatString="o{0}"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 8, 2009 7:42 AM
  • User609686767 posted

    Thanks Hans, i'm trying to research its functionality now,

    Wednesday, April 8, 2009 4:53 PM
  • User609686767 posted

    Thanks Hans, i'm trying to research its functionality now, The delete is working fine without that, but the update is not even if I add it.

    Wednesday, April 8, 2009 5:26 PM