2011-09-27 105 views
0

我有一個網格與網格視圖。我有每行旁邊的更新按鈕。但是當我按下按鈕並編輯字段並按下UPDATE。它不會改變任何東西。下面的代碼:Gridview沒有更新

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

這裏是它我詹姆斯的幫助下截獲查詢:

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 

我到底做錯了什麼?

+0

您可能要包括網格視圖標記爲好。 –

回答

2

我建議添加一個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 
} 
+0

這一個:GridView1_RowUpdating? –

+0

我如何查看commandtext? –

+0

不,使用'SqlDataSource'控件的'OnUpdating'事件。事件參數將包含對將執行的'SqlCommand'對象的引用。 –