1

我有一个使用具有选择、插入、删除和更新功能的 accessdatasource 的 gridview。它曾经完美地工作,但突然间更新停止工作,而其余部分仍在按预期工作。我没有更改 gridview 或数据源中的任何内容,但我向表中添加了新字段但未显示在 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>
4

1 回答 1

1

WHERE 子句中的字段之一:

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

...不匹配记录。可能在一个或多个字段中有尾随空格。

"ABC"不匹配 "ABC "

于 2012-12-11T15:18:54.903 回答