Gridview 中的更新命令停止工作(用于之前工作并删除,选择“工作正常”)



我有一个使用访问数据源的网格视图,它具有选择,插入,删除和更新功能。它曾经完美地工作过,但突然间更新停止工作,而其余的仍在按预期工作。我没有更改网格视图或数据源中的任何内容,但我向表中添加了新字段,但没有显示在网格视图中。我通过从表中删除新字段来进行测试,这些字段也不起作用。还刷新了数据视图和网格视图。这是代码

asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
              ShowFooter="True" EmptyDataText="There are no records for the selection"  
              AutoGenerateColumns="False" CellPadding="4"  OnRowCommand="Insert_Click" 
              OnRowUpdating="beforeUpdate"           
              DataKeyNames="Lab Name,Target,Device Name" 
              ForeColor="#333333" HorizontalAlign="Center" 
              EmptyDataRowStyle-HorizontalAlign="Center" 
              EmptyDataRowStyle-VerticalAlign="Middle" Width="1333px" 
              DataSourceID="AccessDataSource8">
              <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
              <EmptyDataRowStyle Wrap="False" /> 
              <Columns>
                  <asp:TemplateField ShowHeader="False">
                      <EditItemTemplate>
                          <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                              CommandName="Update" Text="Update"></asp:LinkButton>
                          &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                              CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                      </EditItemTemplate>
                      <ItemTemplate>
                          <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                              CommandName="Edit" Text="Edit"></asp:LinkButton>
                          &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                              CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure?');" ></asp:LinkButton>
                      </ItemTemplate>
                      <FooterTemplate>
                     <asp:LinkButton ID="LinkButton" runat="server" CommandName="Insert" Text="Insert" ValidationGroup="validate" ></asp:LinkButton>
                     </FooterTemplate>
                  </asp:TemplateField>
                  <asp:TemplateField HeaderText="Lab Name" SortExpression="Lab Name">
                      <ItemTemplate>
                          <asp:Label ID="Label1" runat="server" Text='<%# Bind("[Lab Name]") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <asp:Label ID="Label1" runat="server" Text='<%# Eval("[Lab Name]") %>'></asp:Label>
                      </EditItemTemplate>
                      <FooterTemplate>
                          <asp:TextBox ID="txtLabname" runat="server" ></asp:TextBox>
                          <asp:RequiredFieldValidator ID="LabName" runat="server" ControlToValidate="txtLabname" Text="*" ValidationGroup="validate"/>
                      </FooterTemplate>
                  </asp:TemplateField>
                  <asp:TemplateField HeaderText="Target" SortExpression="Target">
                      <ItemTemplate>
                          <asp:Label ID="Label2" runat="server" Text='<%# Bind("Target") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <asp:Label ID="Label2" runat="server" Text='<%# Eval("Target") %>'></asp:Label>
                      </EditItemTemplate>
                      <FooterTemplate>
                          <asp:TextBox ID="txtTarget" runat="server" ></asp:TextBox>
                          <asp:RequiredFieldValidator ID="Target" runat="server" ControlToValidate="txtTarget" Text="*" ValidationGroup="validate"/>
                      </FooterTemplate>
                  </asp:TemplateField>
                  <asp:TemplateField HeaderText="Device Name" SortExpression="Device Name">
                      <ItemTemplate>
                          <asp:Label ID="Label3" runat="server" Text='<%# Bind("[Device Name]") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <asp:Label ID="Label3" runat="server" Text='<%# Eval("[Device Name]") %>'></asp:Label>
                      </EditItemTemplate>
                      <FooterTemplate>
                          <asp:TextBox ID="txtDevicename" runat="server" ></asp:TextBox>
                          <asp:RequiredFieldValidator ID="Devicename" runat="server" ControlToValidate="txtDevicename" Text="*" ValidationGroup="validate"/>
                      </FooterTemplate>
                  </asp:TemplateField>
                  <asp:TemplateField HeaderText="IO Type Requirement" 
                      SortExpression="IO Type Requirement">
                      <ItemTemplate>
                          <asp:Label ID="Label4" runat="server" 
                              Text='<%# Bind("[IO Type Requirement]") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <asp:TextBox ID="TextBox1" runat="server" 
                              Text='<%# Bind("[IO Type Requirement]") %>'></asp:TextBox>
                      </EditItemTemplate>
                      <FooterTemplate>
                          <asp:TextBox ID="txtIotyperequirement" runat="server" ></asp:TextBox>
                          <asp:RequiredFieldValidator ID="Iotyperequirement" runat="server" ControlToValidate="txtIotyperequirement" Text="*" ValidationGroup="validate"/>
                      </FooterTemplate>
                  </asp:TemplateField>
                  <asp:TemplateField HeaderText="Part Number" SortExpression="Part Number">
                      <ItemTemplate>
                          <asp:Label ID="Label5" runat="server" Text='<%# Bind("[Part Number]") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("[Part Number]") %>'></asp:TextBox>
                      </EditItemTemplate>
                      <FooterTemplate>
                          <asp:TextBox ID="txtPartnumber" runat="server" ></asp:TextBox>
                          <asp:RequiredFieldValidator ID="Partnumber" runat="server" ControlToValidate="txtPartnumber" Text="*" ValidationGroup="validate"/>
                      </FooterTemplate>
                  </asp:TemplateField>
                  <asp:TemplateField HeaderText="Sub Part" SortExpression="Sub Part">
                      <ItemTemplate>
                          <asp:Label ID="Label6" runat="server" Text='<%# Bind("[Sub Part]") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("[Sub Part]") %>'></asp:TextBox>
                      </EditItemTemplate>
                      <FooterTemplate>
                          <asp:TextBox ID="txtSubpart" runat="server" ></asp:TextBox>
                          <asp:RequiredFieldValidator ID="Subpart" runat="server" ControlToValidate="txtSubpart" Text="*" ValidationGroup="validate"/>
                      </FooterTemplate>
                  </asp:TemplateField>
                  <asp:TemplateField HeaderText="Subpart Description" 
                      SortExpression="Subpart Description">
                      <ItemTemplate>
                          <asp:Label ID="Label7" runat="server" 
                              Text='<%# Bind("[Subpart Description]") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <asp:TextBox ID="TextBox4" runat="server" 
                              Text='<%# Bind("[Subpart Description]") %>'></asp:TextBox>
                      </EditItemTemplate>
                      <FooterTemplate>
                          <asp:TextBox ID="txtSubpartdesc" runat="server" ></asp:TextBox>
                          <asp:RequiredFieldValidator ID="Subpartdesc" runat="server" ControlToValidate="txtSubpartdesc" Text="*" ValidationGroup="validate"/>
                      </FooterTemplate>
                  </asp:TemplateField>
              </Columns>
              <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
              <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
              <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
              <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
              <EditRowStyle BackColor="#999999" VerticalAlign="Middle" Wrap="False" />
              <AlternatingRowStyle BackColor="White" ForeColor="#284775" 
                  VerticalAlign="Middle" Wrap="False" />
          </asp:GridView> 
<asp:AccessDataSource ID="AccessDataSource8" runat="server" CancelSelectOnNullParameter="False" 
                DataFile="~/App_Data/Test.mdb"
                 SelectCommand="SELECT Lab1.[Lab Name], Lab1.[Target], Lab1.[Device Name], Lab1.[IO Type Requirement], Lab1.[Part Number], Lab1.[Sub Part], Lab1.[Subpart Description]
            FROM Lab1 
        WHERE      
         (((Lab1.[Lab Name])= [WhichLab] OR [WhichLab] = '0') AND
        ((Lab1.[Target])= [WhichTarget] OR [WhichTarget] = '0') AND
        ((Lab1.[Device Name])= [WhichDevice] OR [WhichDevice] = '0') AND
        ((Lab1.[IO Type Requirement])= [Whichiotyperequirement] OR [Whichiotyperequirement] = '0') AND
        ((Lab1.[Part Number])= [WhichPartNumber] OR [WhichPartNumber] = '0') AND
        ((Lab1.[Sub Part])= [WhichSubPart] OR [WhichSubPart] = '0') AND
        ((Lab1.[Subpart Description])= [WhichSubPartDesc] OR [WhichSubPartDesc] = '0')
         )" UpdateCommand= " UPDATE  [Lab1] SET  [IO Type Requirement]= ?, [Part Number]= ?, [Sub Part]= ?, [Subpart Description]= ? 
            WHERE ([Lab Name]= ?) AND ([Target]= ?) AND ([Device Name] = ?)"

              InsertCommand= "INSERT INTO LAB1 ([Lab Name],[Target],[Device Name],[IO Type Requirement],[Part Number],[Sub Part],[Subpart Description]) VALUES 
            ([WhichLab],[WhichTarget],[WhichDevice],[Whichiotyperequirement],[WhichPartNumber],[WhichSubPart],[WhichSubPartDesc]) "
            DeleteCommand= " Delete from LAB1 WHERE LAB1.[Lab Name]= [WhichLab] AND Lab1.[Target]=[WhichTarget] AND Lab1.[Device Name]=[WhichDevice]">

                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList1" Name="Lab Name" ConvertEmptyStringToNull="true"  PropertyName="SelectedValue" />
                    <asp:ControlParameter ControlID="DropDownList2" Name="Target" ConvertEmptyStringToNull="true"  PropertyName="SelectedValue" />
                    <asp:ControlParameter ControlID="DropDownList3" Name="Device Name" ConvertEmptyStringToNull="true"  PropertyName="SelectedValue" />
                    <asp:ControlParameter ControlID="DropDownList4" Name="IO Type Requirement" ConvertEmptyStringToNull="true"  PropertyName="SelectedValue" />
                    <asp:ControlParameter ControlID="DropDownList5" Name="Part Number" ConvertEmptyStringToNull="true"  PropertyName="SelectedValue" />
                    <asp:ControlParameter ControlID="DropDownList6" Name="Sub Part" ConvertEmptyStringToNull="true"  PropertyName="SelectedValue" />
                    <asp:ControlParameter ControlID="DropDownList7" Name="Subpart Description" ConvertEmptyStringToNull="true"  PropertyName="SelectedValue" />                                                                    
                </SelectParameters>

                <UpdateParameters>
                    <asp:Parameter  Name="IO Type Requirement"  Type="String"/>
                    <asp:Parameter  Name="Part Number"  Type="String"/>
                    <asp:Parameter  Name="Sub Part" Type="String" />
                    <asp:Parameter  Name="Subpart Description"  Type="String"/>
                    <asp:Parameter  Name="Lab Name"  Type="String"/>
                    <asp:Parameter  Name="Target" Type="String"/>
                    <asp:Parameter  Name="Device Name"  Type="String"/>
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="Lab Name" Type="String" />
                    <asp:Parameter Name="Target" Type="String" />
                    <asp:Parameter Name="Device Name" Type="String" />
                    <asp:Parameter Name="IO Type Requirement" Type="String" />
                    <asp:Parameter Name="Part Number" Type="String" />
                    <asp:Parameter Name="Sub Part" Type="String" />
                    <asp:Parameter Name="Subpart Description" Type="String" />
                </InsertParameters>
                <DeleteParameters>
                    <asp:Parameter Name="Lab Name" Type="String" />
                     <asp:Parameter Name="Target" Type="String" />
                    <asp:Parameter Name="Device Name" Type="String" />

                </DeleteParameters>
            </asp:AccessDataSource>

WHERE 子句中的字段之一:

WHERE ([Lab Name]= ?) AND ([Target]= ?) AND ([Device Name] = ?)"

。与记录不匹配。 也许一个或多个字段中有尾随空格。

"ABC"不会匹配"ABC "

相关内容

  • 没有找到相关文章

最新更新