UPDATE command

topic posted Thu, March 23, 2006 - 7:30 AM by  Grant
I am trying to use the update command for updating fields in a database. When I push the update button the original values are still there any ideas on why this is.....

I am using a details view and specifying update parameters. I don't have anything for pageLoad ....anyway here is the code

<script runat="server">

Protected Sub DetailsView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs)

End Sub

Protected Sub DetailsView1_ItemDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewDeletedEventArgs)
Response.Redirect("default.aspx")
End Sub

Protected Sub DetailsView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewCommandEventArgs)
If e.CommandName = "Cancel" Then
Response.Redirect("default.aspx")
End If
End Sub
</script>

To make changes, click Edit, make your changes, then click Update. To delete
this ad, just click the Delete button.
<br />
<br />
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="100%" AutoGenerateRows="False" DataKeyNames="AdNum" DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None" OnItemUpdated="DetailsView1_ItemUpdated" OnItemDeleted="DetailsView1_ItemDeleted" 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="UserPassword" SortExpression="UserPassword" />
<asp:CommandField ButtonType="Button" ShowDeleteButton="True" ShowEditButton="True" />
</Fields>
<RowStyle BackColor="#FFFBD6" />
<FieldHeaderStyle BackColor="#FFFF99" Font-Bold="True" />
</asp:DetailsView>
 
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:classydbConnectionString %>"
DeleteCommand="DELETE FROM [Ads] WHERE [AdNum] = ? AND [Title] = ? AND [Category] = ? AND [Description] = ? AND [Price] = ? AND [Phone] = ? AND [Email] = ? AND [State] = ? AND [UserPassword] = ?"
ProviderName="<%$ ConnectionStrings:classydbConnectionString.ProviderName %>"
SelectCommand="SELECT [AdNum], [Title], [Category], [Description], [Price], [Phone], [Email], [State], [UserPassword] FROM [Ads] WHERE ([AdNum] = ?)"
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] = ?"
>
<SelectParameters>
<asp:QueryStringParameter Name="AdNum" QueryStringField="AdNum" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="AdNum" 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" />
</UpdateParameters>

</asp:SqlDataSource>
posted by:
Grant
Florida
  • Re: UPDATE command

    Thu, March 23, 2006 - 11:43 AM
    Sorry ...I figured it out after creating a similar page with VSWD express edition and noticing that I was missing a small but vital bit of code:

    Here it is just in case anyone else is having the same problem.

    OldValuesParameterFormatString="original_{0}"

    This would be inserted next line after UPDATE command.

Recent topics in "ASP.net web development"

Topic Author Replies Last Post
graphics in asp Toby 0 August 9, 2008
Does anybody know? Grant 2 January 2, 2008
How to create asp.net pages dynamically? Grant 1 January 2, 2008
question about isPostBack Eira 3 November 2, 2007