Update Fails on FormView
After a miserable afternoon chasing down this bug, I thought it may be helpful to step through why a database update could fail when using the
asp:FormView control.
Symptoms
- The Database Connection String works, because the "Get" is displaying the record.
- The Stored Procedure works, because you ran it inside the database using dummy values.
- You stepped through the wizard to build both the asp:SqlDataSource and asp:FormView controls.
- When you modify a record and click the Update link, the record stays the same. No error is thrown and no changes are made to the database.
Try This
If this is your situation, then you may have the same problem I ran into. Only after I setup debugging in the stored procedure itself did I realize that the asp:FormView was returning a NULL as the primary key. And if a NULL is passed to an UPDATE stored procedure it will execute error free with an updated ROWCOUNT of zero.
My fix was to add the primary key to DataKeyNames field on the asp:FormView.
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="AuthorID">
Labels: ASP.NET, FormView
posted by MAS on Mar 7,2007
Legacy Comments