Editing one record
A form view can read a record and also change it. Switching to edit mode swaps the read only template for an editable one.
The update command
Markup
<asp:SqlDataSource id="oneProduct" runat="server"
ConnectionString="<%$ ConnectionStrings:Shop %>"
SelectCommand="SELECT Id, Name, Price FROM Product WHERE Id = @id"
UpdateCommand="UPDATE Product SET Name = @name, Price = @price WHERE Id = @id">
<UpdateParameters>
<asp:ControlParameter Name="name" ControlID="nameBox" PropertyName="Text" />
<asp:ControlParameter Name="price" ControlID="priceBox" PropertyName="Text" />
<asp:QueryStringParameter Name="id" QueryStringField="id" />
</UpdateParameters>
</asp:SqlDataSource>What to watch
- The update command needs the same identifier parameter as the select, or it will not match a row.
- The edit template must contain controls with the identifiers the parameters expect.
- Convert and validate values before the update runs.
Confirm the save. After updating, show a short confirmation so the visitor knows the change was stored.
Handling a file upload uses the same care with validation, in uploading a file and checking it.