Edit and Update, deleting records and not updating correctly (using Access Database)

Last post 05-09-2008 3:29 PM by Raggers. 5 replies.

Sort Posts:

  • Edit and Update, deleting records and not updating correctly (using Access Database)

    05-07-2008, 8:59 AM
    • Loading...
    • jamvan55
    • Joined on 01-03-2008, 6:26 PM
    • Posts 29

    Hi there, I'm using Visual Studio and linking directly to an access database using the toolbox controls in the program. I'm sure there a better way to code it, but as I'm a rookie , I don't know where to start. Anyway, I have an autonumber ID field and the rest are set as text. I tey to edit the record from the formview and the it works properly, but when I hit the update button the first 3 fields (recordsources) update correctly, but it then deletes the rest of the fields and it's values. I can't for the life of me figure it out. Here is my code and any help would be greatly appreciated;

    <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="HIGHWAY.aspx.vb" Inherits="HIGHWAY" title="Untitled Page" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:AccessDataSource ID="HighwayDataSource" runat="server" DataFile="~/App_Data/NCCAuth.mdb"

    DeleteCommand="DELETE FROM [TblMain] WHERE [ID] = ?" InsertCommand="INSERT INTO [TblMain] ([Auth No], [Caller], [Date], [Time], [H S No], [Type], [Contractor], [Origin], [Destination], [Modification Requested], [Trailer Number], [Pull Date], [Pull Time], [Contractor Date], [Contractor Time], [CDO], [Message Number and comments]) VALUES ('NA-2008', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

    SelectCommand="SELECT * FROM [TblMain]"

    UpdateCommand="UPDATE [TblMain] SET [Auth No] = 'NA-2008', [Caller] = ?, [Date] = ?, [Time] = ?, [H S No] = ?, [Type] = ?, [Contractor] = ?, [Origin] = ?, [Destination] = ?, [Modification Requested] = ?, [Trailer Number] = ?, [Pull Date] = ?, [Pull Time] = ?, [Contractor Date] = ?, [Contractor Time] = ?, [CDO] = ?, [Message Number and comments] = ? WHERE [ID] = ?">

    <DeleteParameters>

    <asp:Parameter Name="ID" Type="Int32" />

    </DeleteParameters>

    <UpdateParameters>

    <asp:Parameter Name="Auth_No" Type="String" />

    <asp:Parameter Name="Caller" Type="String" />

    <asp:Parameter Name="Date" Type="String" />

    <asp:Parameter Name="Time" Type="String" />

    <asp:Parameter Name="H_S_No" Type="String" />

    <asp:Parameter Name="Type" Type="String" />

    <asp:Parameter Name="Contractor" Type="String" />

    <asp:Parameter Name="Origin" Type="String" />

    <asp:Parameter Name="Destination" Type="String" />

    <asp:Parameter Name="Modification_Requested" Type="String" />

    <asp:Parameter Name="Trailer_Number" Type="String" />

    <asp:Parameter Name="Pull_Date" Type="String" />

    <asp:Parameter Name="Pull_Time" Type="String" />

    <asp:Parameter Name="Contractor_Date" Type="String" />

    <asp:Parameter Name="Contractor_Time" Type="String" />

    <asp:Parameter Name="CDO" Type="String" />

    <asp:Parameter Name="Message_Number_and_comments" Type="String" />

    <asp:Parameter Name="ID" Type="Int32" />

    </UpdateParameters>

    <InsertParameters>

    <asp:Parameter Name="ID" Type="Int32" />

    <asp:Parameter Name="Auth_No" Type="String" />

    <asp:Parameter Name="Caller" Type="String" />

    <asp:Parameter Name="Date" Type="String" />

    <asp:Parameter Name="Time" Type="String" />

    <asp:Parameter Name="H_S_No" Type="String" />

    <asp:Parameter Name="Type" Type="String" />

    <asp:Parameter Name="Contractor" Type="String" />

    <asp:Parameter Name="Origin" Type="String" />

    <asp:Parameter Name="Destination" Type="String" />

    <asp:Parameter Name="Modification_Requested" Type="String" />

    <asp:Parameter Name="Trailer_Number" Type="String" />

    <asp:Parameter Name="Pull_Date" Type="String" />

    <asp:Parameter Name="Pull_Time" Type="String" />

    <asp:Parameter Name="Contractor_Date" Type="String" />

    <asp:Parameter Name="Contractor_Time" Type="String" />

    <asp:Parameter Name="CDO" Type="String" />

    <asp:Parameter Name="Message_Number_and_comments" Type="String" />

    </InsertParameters>

    </asp:AccessDataSource>

    <asp:Button ID="Button1" runat="server" PostBackUrl="~/Test.aspx" Text="Add Authorization" />

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"

    DataKeyNames="ID" DataSourceID="HighwayDataSource" ForeColor="#333333" GridLines="None"

    Style="font-size: 8pt; font-family: Arial">

    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

    <Columns>

    <asp:CommandField ShowEditButton="True" />

    <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"

    SortExpression="ID" />

    <asp:BoundField DataField="Auth No" HeaderText="Auth No" SortExpression="Auth No" />

    <asp:BoundField DataField="Caller" HeaderText="Caller" SortExpression="Caller" />

    <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />

    <asp:BoundField DataField="Time" HeaderText="Time" SortExpression="Time" />

    <asp:BoundField DataField="H S No" HeaderText="H S No" SortExpression="H S No" />

    <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />

    <asp:BoundField DataField="Contractor" HeaderText="Contractor" SortExpression="Contractor" />

    <asp:BoundField DataField="Origin" HeaderText="Origin" SortExpression="Origin" />

    <asp:BoundField DataField="Destination" HeaderText="Destination" SortExpression="Destination" />

    <asp:BoundField DataField="Modification Requested" HeaderText="Modification Requested"

    SortExpression="Modification Requested" />

    <asp:BoundField DataField="Trailer Number" HeaderText="Trailer Number" SortExpression="Trailer Number" />

    <asp:BoundField DataField="Pull Date" HeaderText="Pull Date" SortExpression="Pull Date" />

    <asp:BoundField DataField="Pull Time" HeaderText="Pull Time" SortExpression="Pull Time" />

    <asp:BoundField DataField="Contractor Date" HeaderText="Contractor Date" SortExpression="Contractor Date" />

    <asp:BoundField DataField="Contractor Time" HeaderText="Contractor Time" SortExpression="Contractor Time" />

    <asp:BoundField DataField="CDO" HeaderText="CDO" SortExpression="CDO" />

    <asp:BoundField DataField="Message Number and comments" HeaderText="Message Number and comments"

    SortExpression="Message Number and comments" />

    </Columns>

    <RowStyle BackColor="#EFF3FB" />

    <EditRowStyle BackColor="#2461BF" />

    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />

    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />

    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

    <AlternatingRowStyle BackColor="White" />

    </asp:GridView>

    </asp:Content>

  • Re: Edit and Update, deleting records and not updating correctly (using Access Database)

    05-09-2008, 2:55 AM

    Hi jamvan55 ,

    From the code you have posted , I do not find any problem.

    You said the FormView cause the issue. But I do not find FormView from your posted code.

    But some people asked similar questions before . The main problem is that some fields are not been binded correctly.

    For example,

    This can work fine:

      <EditItemTemplate>
                id:
                <asp:Label ID="idLabel1" runat="server" Text='<%# Bind("id") %>' />
                <br />
                name:
                <asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                 <asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
      </EditItemTemplate>

     But in these scenarios below , the name field will be blank.

           <EditItemTemplate>
                id:
                <asp:Label ID="idLabel1" runat="server" Text='<%# Bind("id") %>' />
                <br />
                name:
                <asp:TextBox ID="nameTextBox" runat="server" Text='<%# Eval("name") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                 <asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
    
    
    
           <EditItemTemplate>
                id:
                <asp:Label ID="idLabel1" runat="server" Text='<%# Bind("id") %>' />
                <br />
                name:
                      I delete textbox here!!
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                 <asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>

     

     

    Sincerely,
    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: Edit and Update, deleting records and not updating correctly (using Access Database)

    05-09-2008, 8:23 AM
    • Loading...
    • jamvan55
    • Joined on 01-03-2008, 6:26 PM
    • Posts 29

    I should have chosen different words actually with Formview. What I meant is I have a form with a gridview that has an AccessDataSource configured on it, with the edit enabled under the Datasource, but I do not see anywhere in the code that shows the EditTemplate. How do you edit this template, as it does not pop up under the smart tag?

  • Re: Edit and Update, deleting records and not updating correctly (using Access Database)

    05-09-2008, 8:58 AM
    • Loading...
    • Raggers
    • Joined on 02-17-2006, 11:40 AM
    • Germany
    • Posts 81

     Did you observed....in your insert and update command [Auth No]  is ahving a contant value NA-2008 .Because of this value ur update will have no effect I guess .May be remove that column in

    query and editing  or change to ? or sth else your requiremnt .You change this column to TemplateField simply by clicking convertToTemplate in gridView.columns designer to have complete control

     

     insertCommand="INSERT INTO [TblMain] ([Auth No], [Caller], [Date], [Time], [H S No], [Type], [Contractor], [Origin], [Destination], [Modification Requested], [Trailer Number], [Pull Date], [Pull Time], [Contractor Date], [Contractor Time], [CDO], [Message Number and comments]) VALUES ('NA-2008', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"SelectCommand="SELECT * FROM [TblMain]"

    UpdateCommand="UPDATE [TblMain] SET [Auth No] = 'NA-2008', [Caller] = ?, [Date] = ?, [Time] = ?, [H S No] = ?, [Type] = ?, [Contractor] = ?, [Origin] = ?, [Destination] = ?, [Modification Requested] = ?, [Trailer Number] = ?, [Pull Date] = ?, [Pull Time] = ?, [Contractor Date] = ?, [Contractor Time] = ?, [CDO] = ?, [Message Number and comments] = ? WHERE [ID] = ?">

    If this solves your problem please mark as answer
  • Re: Edit and Update, deleting records and not updating correctly (using Access Database)

    05-09-2008, 10:26 AM
    • Loading...
    • jamvan55
    • Joined on 01-03-2008, 6:26 PM
    • Posts 29

     

    THat worked like a charm, thank you so much for all your help. Have a great weekend!
  • Re: Edit and Update, deleting records and not updating correctly (using Access Database)

    05-09-2008, 3:29 PM
    • Loading...
    • Raggers
    • Joined on 02-17-2006, 11:40 AM
    • Germany
    • Posts 81

    Should have marked as an answer ....! Wink');" sabprocessed="1" title="Wink - Wink">

    If this solves your problem please mark as answer
Page 1 of 1 (6 items)