简体   繁体   中英

Gridview not updating

i have a webform with a gridview. i have the UPDATE button next to each row. however when i press the button and edit the field and press UPDATE. it does not change anything. here's the code:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
    AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" 
    DataKeyNames="lom_number" DataSourceID="SqlDataSource1" ForeColor="#333333" 
    GridLines="None" onselectedindexchanged="GridView1_SelectedIndexChanged">
    <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
    <Columns>
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
            ShowSelectButton="True" />

        <asp:BoundField DataField="occurrence_date" HeaderText="occurrence_date" 
            SortExpression="occurrence_date" />
        <asp:BoundField DataField="report_date" HeaderText="report_date" 
            SortExpression="report_date" />
        <asp:BoundField DataField="report_by" HeaderText="report_by" 
            SortExpression="report_by" />
        <asp:BoundField DataField="identified_by" HeaderText="identified_by" 
            SortExpression="identified_by" />
        <asp:BoundField DataField="section_c_issue_error_identified_by" 
            HeaderText="section_c_issue_error_identified_by" 
            SortExpression="section_c_issue_error_identified_by" />
        <asp:BoundField DataField="section_c_comments" HeaderText="section_c_comments" 
            SortExpression="section_c_comments" />
        <asp:BoundField DataField="section_d_investigation" 
            HeaderText="section_d_investigation" SortExpression="section_d_investigation" />
        <asp:BoundField DataField="section_e_corrective_action" 
            HeaderText="section_e_corrective_action" 
            SortExpression="section_e_corrective_action" />
        <asp:BoundField DataField="section_f_comments" HeaderText="section_f_comments" 
            SortExpression="section_f_comments" />
        <asp:BoundField DataField="pre_practice_code" HeaderText="pre_practice_code" 
            SortExpression="pre_practice_code" />
        <asp:BoundField DataField="pre_contact" HeaderText="pre_contact" 
            SortExpression="pre_contact" />
        <asp:BoundField DataField="lom_number" HeaderText="lom_number" 
            InsertVisible="False" ReadOnly="True" SortExpression="lom_number" />
        <asp:BoundField DataField="windows_user" HeaderText="windows_user" 
            SortExpression="windows_user" />
        <asp:BoundField DataField="computer_name" HeaderText="computer_name" 
            SortExpression="computer_name" />
        <asp:BoundField DataField="time_stamp" HeaderText="time_stamp" 
            SortExpression="time_stamp" />

    </Columns>
    <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
    <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
    <AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:LOM %>" 
    SelectCommand="SELECT * FROM [Main_LOM_Form]" 
    ConflictDetection="CompareAllValues" 
    DeleteCommand="DELETE FROM [Main_LOM_Form] WHERE [lom_number] = @original_lom_number AND (([occurrence_date] = @original_occurrence_date) OR ([occurrence_date] IS NULL AND @original_occurrence_date IS NULL)) AND (([report_date] = @original_report_date) OR ([report_date] IS NULL AND @original_report_date IS NULL)) AND (([report_by] = @original_report_by) OR ([report_by] IS NULL AND @original_report_by IS NULL)) AND (([identified_by] = @original_identified_by) OR ([identified_by] IS NULL AND @original_identified_by IS NULL)) AND (([section_c_issue_error_identified_by] = @original_section_c_issue_error_identified_by) OR ([section_c_issue_error_identified_by] IS NULL AND @original_section_c_issue_error_identified_by IS NULL)) AND (([section_c_comments] = @original_section_c_comments) OR ([section_c_comments] IS NULL AND @original_section_c_comments IS NULL)) AND (([section_d_investigation] = @original_section_d_investigation) OR ([section_d_investigation] IS NULL AND @original_section_d_investigation IS NULL)) AND (([section_e_corrective_action] = @original_section_e_corrective_action) OR ([section_e_corrective_action] IS NULL AND @original_section_e_corrective_action IS NULL)) AND (([section_f_comments] = @original_section_f_comments) OR ([section_f_comments] IS NULL AND @original_section_f_comments IS NULL)) AND (([pre_practice_code] = @original_pre_practice_code) OR ([pre_practice_code] IS NULL AND @original_pre_practice_code IS NULL)) AND (([pre_contact] = @original_pre_contact) OR ([pre_contact] IS NULL AND @original_pre_contact IS NULL)) AND [windows_user] = @original_windows_user AND [computer_name] = @original_computer_name AND [time_stamp] = @original_time_stamp" 
    InsertCommand="INSERT INTO [Main_LOM_Form] ([occurrence_date], [report_date], [report_by], [identified_by], [section_c_issue_error_identified_by], [section_c_comments], [section_d_investigation], [section_e_corrective_action], [section_f_comments], [pre_practice_code], [pre_contact], [windows_user], [computer_name], [time_stamp]) VALUES (@occurrence_date, @report_date, @report_by, @identified_by, @section_c_issue_error_identified_by, @section_c_comments, @section_d_investigation, @section_e_corrective_action, @section_f_comments, @pre_practice_code, @pre_contact, @windows_user, @computer_name, @time_stamp)" 
    OldValuesParameterFormatString="original_{0}" 
    UpdateCommand="UPDATE [Main_LOM_Form] SET [occurrence_date] = @occurrence_date, [report_date] = @report_date, [report_by] = @report_by, [identified_by] = @identified_by, [section_c_issue_error_identified_by] = @section_c_issue_error_identified_by, [section_c_comments] = @section_c_comments, [section_d_investigation] = @section_d_investigation, [section_e_corrective_action] = @section_e_corrective_action, [section_f_comments] = @section_f_comments, [pre_practice_code] = @pre_practice_code, [pre_contact] = @pre_contact, [windows_user] = @windows_user, [computer_name] = @computer_name, [time_stamp] = @time_stamp WHERE [lom_number] = @original_lom_number AND (([occurrence_date] = @original_occurrence_date) OR ([occurrence_date] IS NULL AND @original_occurrence_date IS NULL)) AND (([report_date] = @original_report_date) OR ([report_date] IS NULL AND @original_report_date IS NULL)) AND (([report_by] = @original_report_by) OR ([report_by] IS NULL AND @original_report_by IS NULL)) AND (([identified_by] = @original_identified_by) OR ([identified_by] IS NULL AND @original_identified_by IS NULL)) AND (([section_c_issue_error_identified_by] = @original_section_c_issue_error_identified_by) OR ([section_c_issue_error_identified_by] IS NULL AND @original_section_c_issue_error_identified_by IS NULL)) AND (([section_c_comments] = @original_section_c_comments) OR ([section_c_comments] IS NULL AND @original_section_c_comments IS NULL)) AND (([section_d_investigation] = @original_section_d_investigation) OR ([section_d_investigation] IS NULL AND @original_section_d_investigation IS NULL)) AND (([section_e_corrective_action] = @original_section_e_corrective_action) OR ([section_e_corrective_action] IS NULL AND @original_section_e_corrective_action IS NULL)) AND (([section_f_comments] = @original_section_f_comments) OR ([section_f_comments] IS NULL AND @original_section_f_comments IS NULL)) AND (([pre_practice_code] = @original_pre_practice_code) OR ([pre_practice_code] IS NULL AND @original_pre_practice_code IS NULL)) AND (([pre_contact] = @original_pre_contact) OR ([pre_contact] IS NULL AND @original_pre_contact IS NULL)) AND [windows_user] = @original_windows_user AND [computer_name] = @original_computer_name AND [time_stamp] = @original_time_stamp">
    <DeleteParameters>
        <asp:Parameter Name="original_lom_number" Type="Int32" />
        <asp:Parameter DbType="Date" Name="original_occurrence_date" />
        <asp:Parameter DbType="Date" Name="original_report_date" />
        <asp:Parameter Name="original_report_by" Type="String" />
        <asp:Parameter Name="original_identified_by" Type="String" />
        <asp:Parameter Name="original_section_c_issue_error_identified_by" 
            Type="String" />
        <asp:Parameter Name="original_section_c_comments" Type="String" />
        <asp:Parameter Name="original_section_d_investigation" Type="String" />
        <asp:Parameter Name="original_section_e_corrective_action" Type="String" />
        <asp:Parameter Name="original_section_f_comments" Type="String" />
        <asp:Parameter Name="original_pre_practice_code" Type="String" />
        <asp:Parameter Name="original_pre_contact" Type="String" />
        <asp:Parameter Name="original_windows_user" Type="String" />
        <asp:Parameter Name="original_computer_name" Type="String" />
        <asp:Parameter Name="original_time_stamp" Type="DateTime" />
    </DeleteParameters>
    <UpdateParameters>
        <asp:Parameter DbType="Date" Name="occurrence_date" />
        <asp:Parameter DbType="Date" Name="report_date" />
        <asp:Parameter Name="report_by" Type="String" />
        <asp:Parameter Name="identified_by" Type="String" />
        <asp:Parameter Name="section_c_issue_error_identified_by" Type="String" />
        <asp:Parameter Name="section_c_comments" Type="String" />
        <asp:Parameter Name="section_d_investigation" Type="String" />
        <asp:Parameter Name="section_e_corrective_action" Type="String" />
        <asp:Parameter Name="section_f_comments" Type="String" />
        <asp:Parameter Name="pre_practice_code" Type="String" />
        <asp:Parameter Name="pre_contact" Type="String" />
        <asp:Parameter Name="windows_user" Type="String" />
        <asp:Parameter Name="computer_name" Type="String" />
        <asp:Parameter Name="time_stamp" Type="DateTime" />
        <asp:Parameter Name="original_lom_number" Type="Int32" />
        <asp:Parameter DbType="Date" Name="original_occurrence_date" />
        <asp:Parameter DbType="Date" Name="original_report_date" />
        <asp:Parameter Name="original_report_by" Type="String" />
        <asp:Parameter Name="original_identified_by" Type="String" />
        <asp:Parameter Name="original_section_c_issue_error_identified_by" 
            Type="String" />
        <asp:Parameter Name="original_section_c_comments" Type="String" />
        <asp:Parameter Name="original_section_d_investigation" Type="String" />
        <asp:Parameter Name="original_section_e_corrective_action" Type="String" />
        <asp:Parameter Name="original_section_f_comments" Type="String" />
        <asp:Parameter Name="original_pre_practice_code" Type="String" />
        <asp:Parameter Name="original_pre_contact" Type="String" />
        <asp:Parameter Name="original_windows_user" Type="String" />
        <asp:Parameter Name="original_computer_name" Type="String" />
        <asp:Parameter Name="original_time_stamp" Type="DateTime" />
    </UpdateParameters>
    <InsertParameters>
        <asp:Parameter DbType="Date" Name="occurrence_date" />
        <asp:Parameter DbType="Date" Name="report_date" />
        <asp:Parameter Name="report_by" Type="String" />
        <asp:Parameter Name="identified_by" Type="String" />
        <asp:Parameter Name="section_c_issue_error_identified_by" Type="String" />
        <asp:Parameter Name="section_c_comments" Type="String" />
        <asp:Parameter Name="section_d_investigation" Type="String" />
        <asp:Parameter Name="section_e_corrective_action" Type="String" />
        <asp:Parameter Name="section_f_comments" Type="String" />
        <asp:Parameter Name="pre_practice_code" Type="String" />
        <asp:Parameter Name="pre_contact" Type="String" />
        <asp:Parameter Name="windows_user" Type="String" />
        <asp:Parameter Name="computer_name" Type="String" />
        <asp:Parameter Name="time_stamp" Type="DateTime" />
    </InsertParameters>
</asp:SqlDataSource>

here is the query that it i intercepted with james' help:

updateQuery "UPDATE [Main_LOM_Form] SET [occurrence_date] = @occurrence_date, [report_date] = @report_date, [report_by] = @report_by, [identified_by] = @identified_by, [section_c_issue_error_identified_by] = @section_c_issue_error_identified_by, [section_c_comments] = @section_c_comments, [section_d_investigation] = @section_d_investigation, [section_e_corrective_action] = @section_e_corrective_action, [section_f_comments] = @section_f_comments, [pre_practice_code] = @pre_practice_code, [pre_contact] = @pre_contact, [windows_user] = @windows_user, [computer_name] = @computer_name, [time_stamp] = @time_stamp WHERE [lom_number] = @original_lom_number AND (([occurrence_date] = @original_occurrence_date) OR ([occurrence_date] IS NULL AND @original_occurrence_date IS NULL)) AND (([report_date] = @original_report_date) OR ([report_date] IS NULL AND @original_report_date IS NULL)) AND (([report_by] = @original_report_by) OR ([report_by] IS NULL AND @original_report_by IS NULL)) AND (([identified_by] = @original_identified_by) OR ([identified_by] IS NULL AND @original_identified_by IS NULL)) AND (([section_c_issue_error_identified_by] = @original_section_c_issue_error_identified_by) OR ([section_c_issue_error_identified_by] IS NULL AND @original_section_c_issue_error_identified_by IS NULL)) AND (([section_c_comments] = @original_section_c_comments) OR ([section_c_comments] IS NULL AND @original_section_c_comments IS NULL)) AND (([section_d_investigation] = @original_section_d_investigation) OR ([section_d_investigation] IS NULL AND @original_section_d_investigation IS NULL)) AND (([section_e_corrective_action] = @original_section_e_corrective_action) OR ([section_e_corrective_action] IS NULL AND @original_section_e_corrective_action IS NULL)) AND (([section_f_comments] = @original_section_f_comments) OR ([section_f_comments] IS NULL AND @original_section_f_comments IS NULL)) AND (([pre_practice_code] = @original_pre_practice_code) OR ([pre_practice_code] IS NULL AND @original_pre_practice_code IS NULL)) AND (([pre_contact] = @original_pre_contact) OR ([pre_contact] IS NULL AND @original_pre_contact IS NULL)) AND [windows_user] = @original_windows_user AND [computer_name] = @original_computer_name AND [time_stamp] = @original_time_stamp"    string

what am i doing wrong?

I would suggest adding an OnUpdating event handler so you can look at the CommandText before the query is executed. That should help you identify if there's an issue with the query.

In the markup:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" OnUpdating="SqlDataSource1_Updating" ... >

In the code-behind:

protected void SqlDataSource1_Updating(object sender, SqlDataSourceCommandEventArgs e)
{    
    string updateQuery = e.Command.CommandText;

    //inspect the update query
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM