我正在尝试让用户在此网格视图中选择一行,并在窗体视图中显示有关该条目的一组详细信息。目前,我收到错误“无效的列名称'sSprayId'”。我遇到了几个问题而且出于想法。我在下面发布了我的代码。关于如何解决这个或更好的方法的任何想法?谢谢。
<asp:GridView ID="gvHistory" runat="server" DataSourceID="dsHistory" AllowPaging="True" AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="None" DataKeyNames="SprayId">
<AlternatingRowStyle BackColor="White" ForeColor="#284775"></AlternatingRowStyle>
<Columns>
<asp:CommandField ShowSelectButton="True"></asp:CommandField>
</Columns>
<EditRowStyle BackColor="#999999"></EditRowStyle>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></FooterStyle>
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></HeaderStyle>
<PagerStyle HorizontalAlign="Center" BackColor="#284775" ForeColor="White"></PagerStyle>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333"></RowStyle>
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"></SelectedRowStyle>
<SortedAscendingCellStyle BackColor="#E9E7E2"></SortedAscendingCellStyle>
<SortedAscendingHeaderStyle BackColor="#506C8C"></SortedAscendingHeaderStyle>
<SortedDescendingCellStyle BackColor="#FFFDF8"></SortedDescendingCellStyle>
<SortedDescendingHeaderStyle BackColor="#6F8DAE"></SortedDescendingHeaderStyle>
</asp:GridView>
<asp:SqlDataSource ID="dsHistory" runat="server" ConnectionString='<%$ ConnectionStrings:WSFConnectionString %>' SelectCommand="SELECT [SprayId], [Date], [TimeStart] FROM [Spray] WHERE ([Date] >= (GETDATE() - 7)) ORDER BY [Date] DESC, [TimeStart] DESC"></asp:SqlDataSource>
<asp:FormView ID="fvHistoryDetail" runat="server" CellPadding="4" ForeColor="#333333" DataSourceID="dsHistoryDetail" DataKeyNames="SprayId">
<EditItemTemplate>
SprayId:
<asp:Label Text='<%# Eval("SprayId") %>' runat="server" ID="SprayIdLabel1" /><br />
<asp:LinkButton runat="server" Text="Update" CommandName="Update" ID="UpdateButton" CausesValidation="True" /> <asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" ID="UpdateCancelButton" CausesValidation="False" />
</EditItemTemplate>
<EditRowStyle BackColor="#999999"></EditRowStyle>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></FooterStyle>
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></HeaderStyle>
<InsertItemTemplate>
<asp:LinkButton runat="server" Text="Insert" CommandName="Insert" ID="InsertButton" CausesValidation="True" /> <asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" ID="InsertCancelButton" CausesValidation="False" />
</InsertItemTemplate>
<ItemTemplate>
SprayId:
<asp:Label Text='<%# Eval("SprayId") %>' runat="server" ID="SprayIdLabel" /><br />
</ItemTemplate>
<PagerStyle HorizontalAlign="Center" BackColor="#284775" ForeColor="White"></PagerStyle>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333"></RowStyle>
</asp:FormView>
<asp:SqlDataSource ID="dsHistoryDetail" runat="server" ConnectionString='<%$ ConnectionStrings:WSFConnectionString %>' SelectCommand="SELECT s.SprayId as 'ID', [Date], TimeStart as 'Time Start', StartLocationDescription as 'Start', EndLocationDescription as 'End', v.VehicleNumber, (a.FirstName + a.LastName) as 'Applicator', c.TradeName as 'Chemical' FROM Spray s join Vehicle v on s.VehicleId = v.VehicleId join Applicator a on s.Applicator1Id = a.ApplicatorId join SprayChemicalsUsed scu on scu.SprayId = s.SprayId join ChemicalsUsed cu on scu.ChemUsedId = cu.ChemUsedId join Chemical c on cu.ChemId = c.ChemId WHERE ([s.SprayId] = @SprayId)">
<SelectParameters>
<asp:ControlParameter ControlID="gvHistory" PropertyName="SelectedValue" DefaultValue="1" Name="SprayId" Type="Int32"></asp:ControlParameter>
</SelectParameters>
</asp:SqlDataSource>
答案 0 :(得分:0)
问题在于您的select命令查询:
SELECT s.SprayId as 'ID', [Date], TimeStart as 'Time Start', StartLocationDescription as 'Start', EndLocationDescription as 'End', v.VehicleNumber, (a.FirstName + a.LastName) as 'Applicator', c.TradeName as 'Chemical' FROM Spray s join Vehicle v on s.VehicleId = v.VehicleId join Applicator a on s.Applicator1Id = a.ApplicatorId join SprayChemicalsUsed scu on scu.SprayId = s.SprayId join ChemicalsUsed cu on scu.ChemUsedId = cu.ChemUsedId join Chemical c on cu.ChemId = c.ChemId WHERE ([s.SprayId] = @SprayId)
该列是否存在且名称正确将是首先要检查的。
我会在SQL管理查询或您正在使用的任何数据库工具中打开它,并让它首先在那里工作。显而易见的是,GUI将突出显示SQL语法中的错误。