View Single Post
  #1 (permalink)  
Old November 20th, 2012, 09:30 AM
scott100 scott100 is offline
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default DetailView Update not working.

Hi all, new member stuck so need some help please

I'm following page 410 - Beginning ASP.NET 3.5


DB Name
  • dbo.A_TEST_SCOTT

Columns:
  • id (PK, int, not null)
  • name (varchar(50), null)
  • address (varchar(50), null)


I can insert OK into the database
I can't update, when i try to do this and check the results, nothing has changed :(

My DetailsView page is displaying the record ok based on the query string parameter so ?id=2 and ?id=3 pull through different records fine.


Here is my code, all drap and drop:

Code:
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
        DataKeyNames="id" DataSourceID="SqlDataSource1" DefaultMode="Insert" 
        Height="50px" Width="125px">
        <Fields>
            <asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" />
            <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
            <asp:BoundField DataField="address" HeaderText="address" SortExpression="address" />
            <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
        </Fields>
    </asp:DetailsView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Commercial_db %>" 
        DeleteCommand="DELETE FROM [A_TEST_SCOTT] WHERE [id] = @id" 
        InsertCommand="INSERT INTO [A_TEST_SCOTT] ([id], [name], [address]) VALUES (@id, @name, @address)" 
        SelectCommand="SELECT [id], [name], [address] FROM [A_TEST_SCOTT] WHERE ([id] = @id)" 
        UpdateCommand="UPDATE [A_TEST_SCOTT] SET [name] = @name, [address] = @address WHERE [id] = @id">
        <SelectParameters>
            <asp:QueryStringParameter Name="id" QueryStringField="id" Type="Int32" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="id" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="name" Type="String" />
            <asp:Parameter Name="address" Type="String" />
            <asp:Parameter Name="id" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="id" Type="Int32" />
            <asp:Parameter Name="name" Type="String" />
            <asp:Parameter Name="address" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>

Code Behind

Code:
        
protected void Page_Load(object sender, EventArgs e)
{
    if (Request.QueryString.Get("id") != null)
    {
       DetailsView1.DefaultMode = DetailsViewMode.Edit;
    }
}


any advise appreciated