locked
FormView Update - Problem updating RRS feed

  • Question

  • User-1874295183 posted
    I have a C# webform which uses a formview to insert, update, and delete records selected from a gridview into an Access database. The insert and delete functions work fine, the update does not.
    • The formview has 'id' as a DataKeyName.
    • The update works if done from the Query Builder and I enter the values manually
    • I don't have anything in the codebehind for the update event.

    UpdateCommand:

    1. UpdateCommand=
    2. "UPDATE CM_Codebase 
    3. SET 
    4. build_label = ?
    5. , program_type = ?
    6. , program_name = ?
    7. , ticket_status = ?
    8. , push_number = ?
    9. , approved = ?
    10. , comments = ? 
    11. WHERE 
    12. (id = ?)"

    UpdateParameters:

    1. <UpdateParameters>
    2.             <asp:Parameter Name="build_label" />
    3.             <asp:Parameter Name="program_type" />
    4.             <asp:Parameter Name="program_name" />
    5.             <asp:Parameter Name="ticket_status" />
    6.             <asp:Parameter Name="push_number" />
    7.             <asp:Parameter Name="approved" />
    8.             <asp:Parameter Name="comments" />
    9.             <asp:Parameter Name="id" Type="Int32"  />
    10.         </UpdateParameters>


    FormView Definition:
    1. <asp:FormView ID="FormView1" 
    2. runat="server" BackColor="LightGoldenrodYellow" 
    3. BorderColor="Tan" BorderWidth="1px" 
    4. CellPadding="2" DataKeyNames="id" 
    5. DataMember="DefaultView" DataSourceID="AccessDataSource1" 
    6. ForeColor="Black" HorizontalAlign="Center">
    7. <FooterStyle BackColor="Tan" />


    Update Button:

    1. <asp:LinkButton ID="UpdateButton" 
    2. runat="server" CausesValidation="True" 
    3. CommandName="Update" 
    4. Text="Update">


     
    I'm not getting an error. The command proceeds as normal, like it's actually updating, then the page does the postback and everything is the same.

    I've added some code to debug it...
    1. protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    2.     {
    3.         object comments = e.OldValues["comments"];
    4.         object newcomment = e.NewValues["comments"];
    5.     }
    Now, looking at the Autos debug window I see that it's getting the new value for the "comments" field, I changed the value to "Comment1" just so it would stick out. The old value was "NO COMMENT"

    So, when I update the field and click the Update link button, it's getting the new value but for some reason not storing it.

    What to do...

    Also, it's getting the key "id" just fine with its value of "10" so I'm not sure what to check next...
     
    Is there any way to see the SQL statement it's trying to use? If I just write out the update command it's giving me all the "?"'s but what I want to see are my variables in there.

     

    Monday, December 8, 2008 9:40 AM

All replies

  • User-1874295183 posted

     This is resolved. I just wrote an update function manually in the codebehind.

    Tuesday, December 9, 2008 11:36 AM
  • User-1199946673 posted

    A workaround is not same as 'resolved'...

    Everything looks fine to me, the only thing I can think that may be the issue is that you didn't set the type of the parameters!

    Tuesday, December 9, 2008 11:48 AM