Gridview not updating

本文关键字:updating not Gridview | 更新日期: 2023-09-27 18:09:43

我有一个带有gridview的webform。我有更新按钮旁边的每一行。然而,当我按下按钮和编辑字段,并按下更新。这不会改变任何事情。下面是代码:

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

下面是我在james的帮助下截获的查询:

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

我做错了什么?

Gridview not updating

我建议添加一个OnUpdating事件处理程序,这样您就可以在执行查询之前查看CommandText。这样可以帮助您确定查询是否有问题。

标记:

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

在代码后面:

protected void SqlDataSource1_Updating(object sender, SqlDataSourceCommandEventArgs e)
{    
    string updateQuery = e.Command.CommandText;
    //inspect the update query
}