Visual C# Webform - FormView Update Not Working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • somacore
    New Member
    • Apr 2008
    • 24

    #1

    Visual C# Webform - FormView Update Not Working

    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:
    Code:
    UpdateCommand=
    "UPDATE CM_Codebase 
    SET 
    build_label = ?
    , program_type = ?
    , program_name = ?
    , ticket_status = ?
    , push_number = ?
    , approved = ?
    , comments = ? 
    WHERE 
    (id = ?)"
    UpdateParameter s:
    Code:
    <UpdateParameters>
                <asp:Parameter Name="build_label" />
                <asp:Parameter Name="program_type" />
                <asp:Parameter Name="program_name" />
                <asp:Parameter Name="ticket_status" />
                <asp:Parameter Name="push_number" />
                <asp:Parameter Name="approved" />
                <asp:Parameter Name="comments" />
                <asp:Parameter Name="id"  />
            </UpdateParameters>
    FormView Definition:
    Code:
    <asp:FormView ID="FormView1" 
    runat="server" BackColor="LightGoldenrodYellow" 
    BorderColor="Tan" BorderWidth="1px" 
    CellPadding="2" DataKeyNames="id" 
    DataMember="DefaultView" DataSourceID="AccessDataSource1" 
    ForeColor="Black" HorizontalAlign="Center">
    <FooterStyle BackColor="Tan" />
    Update Button:
    Code:
    <asp:LinkButton ID="UpdateButton" 
    runat="server" CausesValidation="True" 
    CommandName="Update" 
    Text="Update">
    Any help is appreciated.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    What error message are you getting?
    If you are not getting an error at all, it usually means that it found no record to update.

    Comment

    • somacore
      New Member
      • Apr 2008
      • 24

      #3
      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...

      Code:
      protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
          {
              object comments = e.OldValues["comments"];
              object newcomment = e.NewValues["comments"];
          }
      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 "BYZANTINE" just so it would stick out. The old value was "WHAT"

      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...

      edit: Also, it's getting the key "id" just fine with its value of "10" so I'm not sure what to check next...

      Edit again: 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.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Hmm, I don't normally do data processing in the design section.
        Nothing happens in your page load that populates or clears these values right?
        You don't need to do any checking for isPostBack ?

        Comment

        • Filip Baeke
          New Member
          • Sep 2010
          • 2

          #5
          I'm having exactly the same problem as Somacore.
          Did you find a solution ?

          Comment

          • Filip Baeke
            New Member
            • Sep 2010
            • 2

            #6
            I removed ConflictDetecti on="CompareAllV alues" in my SQLdatasource and now it works fine !

            Comment

            Working...