none
Update Button not updating data in FormView RRS feed

  • Question

  • I have created a page linked to a simple Access .mdb database.  The page finds and displays a record I want correctly. I select Edit and change a value and click Update.  The page resets but the data is not changed.  I have tried Grid View and Form View.  I have used the EW4 wizards to create the AccessDataCource and two forms and have not changed any code.

    I have checked that there is a Primary Key field.  The other fields are either date or text fields.  The page won't update on local host either so don't think it's a permissions issue.  Just in case I checked and the ISP said the folders are not write protected.  The relevant pages are password protected so that  only approved users can access them but the ISP reckons that will not affect ability to update the database.  Similar sites with same ISP work fine so assume the ISP is right about this. 

    I have had this problem before on other sites and managed to resolve (can't remember how).  I have compared them with the new site and can't see any differences.  I think it is probably something very simple.  Any ideas...

    Tuesday, August 28, 2012 12:47 PM

Answers

  • Thanks for help  I have resolved it myself now.  As I thought it was a simple solution.

    It appears to be a fault in the way the Wizard that creates the AccessDataSource works.  After you have selected the Access database you are prompted to select the table that contains the data.  EW4 automatically selects all fields in the table by putting a tick alongside the *.  You then pick any selection criteria and Advanced option etc. to complete the wizard.  Whenever I tried this on any of my three PCs loaded with EW4 I had the same effect - the data would display but you could not edit it.  If instead of allowing a tick alongside the * symbol you manually ticked each field in the table, leaving the Prime Key field until last, it always worked.  I can now update the data correctly.

    I can't see for the life on me why this works or matters but there you go, it does. 


    Bob @ Gryphon

    • Marked as answer by gryphonmedia Wednesday, August 29, 2012 4:26 PM
    Wednesday, August 29, 2012 4:26 PM

All replies

  • We, of course, not only can't see the difference, but can't see what you've done at all.

    Normally I would send you to the asp.net forum for an asp.net question that requires seeing the code, but I'll suggest you post it here if you promise to do the following:

    Create a page with nothing else on it other than your datasource and the gridview enabled for editing.

    If that page doesn't work, post the Code View of that *very short* aspx page here.


    • Edited by KathyW2 Tuesday, August 28, 2012 1:16 PM
    Tuesday, August 28, 2012 1:14 PM
  • OK - thought there may be a simple answer

    Try http://ap-shipspares.co.uk/packer_update.aspx


    Bob @ Gryphon

    Tuesday, August 28, 2012 1:52 PM
  • No, not a link.  That does not contain the asp.net code, but rather the HTML sent to the browser after the asp.net framework processes the asp.net code.  For HTML pages, a link is what we need.  That's not the case for asp.net pages.

    As to "thought there may be a simple answer" - well, there might be.  But from your written description, how would we know what it would be?  If you re-read it, it basically says, "I did it correctly, it has worked before, I can't see a difference, what did I do wrong this time?", and there is nothing for us to look at.

    Tuesday, August 28, 2012 1:58 PM
  • As requested here is the code:-

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@ Page Language="C#" %>
    <html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">
    <meta content="en-gb" http-equiv="Content-Language" />
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>Welcome</title>
    <style type="text/css">
    .auto-style1 {
     text-align: center;
    }
    .auto-style4 {
     font-family: Arial, Helvetica, sans-serif;
     font-size: large;
    }
    .auto-style5 {
     margin-right: 40px;
    }
    .auto-style6 {
     text-align: left;
    }
    .auto-style7 {
     font-family: Georgia, "Times New Roman", Times, serif;
     font-size: 60pt;
     text-align: center;
    }
    </style>
    </head>

    <body>

    <form id="form1" runat="server">
     <table align="center" cellpadding="0" cellspacing="0" style="width: 955px">
      <tr>
       <td class="auto-style7" style="height: 91px">
       <em>Gryphon Media </em></td>
      </tr>
      <tr>
       <td class="auto-style1" style="height: 345px">
       <span class="auto-style4"><br />
       There are a number of records in the table.&nbsp; Enter '720521/4'
       to find that record, for example.<br />
       When I select Edit, change a record and press Update the record is
       not updated.<br />
       <br />
       I have used basic wizards and have not changed any code.<br />
       <br />
       </span>
       <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
       <br />
       <br />
       <br />
       <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="apdata/web_export.mdb" DeleteCommand="DELETE FROM [webexport] WHERE [PrimeID] = ?" InsertCommand="INSERT INTO [webexport] ([search], [Required Delivery Date], [Tender Issued Date], [Tender Closing Date], [Date Ordered], [Deadline to Packer], [Date Received by Packer], [Date Packed], [Date Reported for Collection], [Collection Date], [Collection Note Ref], [Courier], [Proof of Collection]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" SelectCommand="SELECT * FROM [webexport] WHERE ([search] LIKE '%' + ? + '%') ORDER BY [Date Received by Packer]" UpdateCommand="UPDATE [webexport] SET [search] = ?, [Required Delivery Date] = ?, [Tender Issued Date] = ?, [Tender Closing Date] = ?, [Date Ordered] = ?, [Deadline to Packer] = ?, [Date Received by Packer] = ?, [Date Packed] = ?, [Date Reported for Collection] = ?, [Collection Date] = ?, [Collection Note Ref] = ?, [Courier] = ?, [Proof of Collection] = ? WHERE [PrimeID] = ?">
        <DeleteParameters>
         <asp:Parameter Name="PrimeID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
         <asp:Parameter Name="search" Type="String" />
         <asp:Parameter Name="Required_Delivery_Date" Type="DateTime" />
         <asp:Parameter Name="Tender_Issued_Date" Type="DateTime" />
         <asp:Parameter Name="Tender_Closing_Date" Type="DateTime" />
         <asp:Parameter Name="Date_Ordered" Type="DateTime" />
         <asp:Parameter Name="Deadline_to_Packer" Type="DateTime" />
         <asp:Parameter Name="Date_Received_by_Packer" Type="DateTime" />
         <asp:Parameter Name="Date_Packed" Type="DateTime" />
         <asp:Parameter Name="Date_Reported_for_Collection" Type="DateTime" />
         <asp:Parameter Name="Collection_Date" Type="DateTime" />
         <asp:Parameter Name="Collection_Note_Ref" Type="String" />
         <asp:Parameter Name="Courier" Type="String" />
         <asp:Parameter Name="Proof_of_Collection" Type="String" />
        </InsertParameters>
        <SelectParameters>
         <asp:ControlParameter ControlID="TextBox1" Name="search" PropertyName="Text" Type="String" />
        </SelectParameters>
        <UpdateParameters>
         <asp:Parameter Name="search" Type="String" />
         <asp:Parameter Name="Required_Delivery_Date" Type="DateTime" />
         <asp:Parameter Name="Tender_Issued_Date" Type="DateTime" />
         <asp:Parameter Name="Tender_Closing_Date" Type="DateTime" />
         <asp:Parameter Name="Date_Ordered" Type="DateTime" />
         <asp:Parameter Name="Deadline_to_Packer" Type="DateTime" />
         <asp:Parameter Name="Date_Received_by_Packer" Type="DateTime" />
         <asp:Parameter Name="Date_Packed" Type="DateTime" />
         <asp:Parameter Name="Date_Reported_for_Collection" Type="DateTime" />
         <asp:Parameter Name="Collection_Date" Type="DateTime" />
         <asp:Parameter Name="Collection_Note_Ref" Type="String" />
         <asp:Parameter Name="Courier" Type="String" />
         <asp:Parameter Name="Proof_of_Collection" Type="String" />
         <asp:Parameter Name="PrimeID" Type="Int32" />
        </UpdateParameters>
       </asp:AccessDataSource>
       <div class="auto-style6">
        <asp:DetailsView id="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False" CellPadding="4" CssClass="auto-style5" DataKeyNames="PrimeID" DataSourceID="AccessDataSource1" Font-Names="Arial,Helvetica,sans-serif" Font-Size="Small" ForeColor="#333333" GridLines="None" Height="50px" Width="560px" HorizontalAlign="Center">
         <AlternatingRowStyle BackColor="White" />
         <CommandRowStyle BackColor="#C5BBAF" Font-Bold="True" />
         <EditRowStyle BackColor="#7C6F57" />
         <FieldHeaderStyle BackColor="#D0D0D0" Font-Bold="True" />
         <Fields>
          <asp:BoundField DataField="Proof of Collection" HeaderText="Proof of Collection" SortExpression="Proof of Collection">
          </asp:BoundField>
          <asp:BoundField DataField="PrimeID" HeaderText="PrimeID" InsertVisible="False" ReadOnly="True" SortExpression="PrimeID">
          </asp:BoundField>
          <asp:BoundField DataField="search" HeaderText="search" SortExpression="search">
          </asp:BoundField>
          <asp:BoundField DataField="Required Delivery Date" HeaderText="Required Delivery Date" SortExpression="Required Delivery Date">
          </asp:BoundField>
          <asp:BoundField DataField="Tender Issued Date" HeaderText="Tender Issued Date" SortExpression="Tender Issued Date">
          </asp:BoundField>
          <asp:BoundField DataField="Tender Closing Date" HeaderText="Tender Closing Date" SortExpression="Tender Closing Date">
          </asp:BoundField>
          <asp:BoundField DataField="Date Ordered" HeaderText="Date Ordered" SortExpression="Date Ordered">
          </asp:BoundField>
          <asp:BoundField DataField="Deadline to Packer" HeaderText="Deadline to Packer" SortExpression="Deadline to Packer">
          </asp:BoundField>
          <asp:BoundField DataField="Date Received by Packer" HeaderText="Date Received by Packer" SortExpression="Date Received by Packer">
          </asp:BoundField>
          <asp:BoundField DataField="Date Packed" HeaderText="Date Packed" SortExpression="Date Packed">
          </asp:BoundField>
          <asp:BoundField DataField="Date Reported for Collection" HeaderText="Date Reported for Collection" SortExpression="Date Reported for Collection">
          </asp:BoundField>
          <asp:BoundField DataField="Collection Date" HeaderText="Collection Date" SortExpression="Collection Date">
          </asp:BoundField>
          <asp:BoundField DataField="Collection Note Ref" HeaderText="Collection Note Ref" SortExpression="Collection Note Ref">
          </asp:BoundField>
          <asp:BoundField DataField="Courier" HeaderText="Courier" SortExpression="Courier">
          </asp:BoundField>
          <asp:CommandField ShowEditButton="True">
          </asp:CommandField>
         </Fields>
         <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
         <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
         <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
         <RowStyle BackColor="#E3EAEB" />
        </asp:DetailsView>
       </div>
       </td>
      </tr>
      <tr>
       <td>&nbsp;</td>
      </tr>
     </table>
    </form>

    </body>

    </html>


    Bob @ Gryphon

    Tuesday, August 28, 2012 2:29 PM
  • I can't spot anything in your code that would explain your problem.

    I can only suggest starting smaller and debugging:  Create a small, simple table in your database with a primary id column and a couple text columns, and see if that works.  If it does, gradually make changes to match what you are using in that page and see what changes cause the problem.


    • Edited by KathyW2 Tuesday, August 28, 2012 5:23 PM
    Tuesday, August 28, 2012 3:11 PM
  • Thanks for help  I have resolved it myself now.  As I thought it was a simple solution.

    It appears to be a fault in the way the Wizard that creates the AccessDataSource works.  After you have selected the Access database you are prompted to select the table that contains the data.  EW4 automatically selects all fields in the table by putting a tick alongside the *.  You then pick any selection criteria and Advanced option etc. to complete the wizard.  Whenever I tried this on any of my three PCs loaded with EW4 I had the same effect - the data would display but you could not edit it.  If instead of allowing a tick alongside the * symbol you manually ticked each field in the table, leaving the Prime Key field until last, it always worked.  I can now update the data correctly.

    I can't see for the life on me why this works or matters but there you go, it does. 


    Bob @ Gryphon

    • Marked as answer by gryphonmedia Wednesday, August 29, 2012 4:26 PM
    Wednesday, August 29, 2012 4:26 PM
  • Actually, it's not an error in EW's wizard.   If you ask it to create "SELECT *", it will.  If you ask it to create "SELECT [column1], [column2], ...", it will.

    This issue was discovering that SELECT * doesn't work for all cases where SELECT [column1], [column2]... will.  That relates to how ACCESS and the data control (in this case your DetailsView) are communicating and passing the values back and forth.  The simple thing to do is just always explicitly select your table columns.  Leave "SELECT *" for the case where all you are doing with the data is selecting it and displaying it.

    Wednesday, August 29, 2012 5:11 PM
  • OK - if that's the case why don't Microsoft put something to that effect either in a help file or put a warning in the body of the Wizard.  It's not much help providing a wizard that has a default way of working that doesn't work correctly.   


    Bob @ Gryphon

    Wednesday, August 29, 2012 5:53 PM
  • I can not tell you that.  I am not Microsoft, and you are not talking to Microsoft when you are posting here.

    Wednesday, August 29, 2012 7:22 PM