我无法让任何查询工作。当我在Access中使用它们时它们可以工作。出于某种原因,我无法让他们为我的网站工作。我错过了一些代码背后的东西吗?当我使用QueryString参数时,我应该有什么代码吗?以下是我之前关于之前查询的帖子:
这是我当前的查询和相关的ASP代码:
StreetPhoto.aspx
<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile="~/App_Data/TravelJoansDB.accdb"
SelectCommand="SELECT * FROM [StreetPhotos]">
</asp:AccessDataSource>
<asp:DataList ID="DataList2" runat="server"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="30"
CellSpacing="2" DataKeyField="ID" DataSourceID="AccessDataSource2"
GridLines="Both" RepeatColumns="3" RepeatDirection="Horizontal">
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<ItemStyle BackColor="White" />
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "StreetPic.aspx?ID=" + Eval("ID") %>'>
<asp:Image ID="Image1" runat="server" AlternateText="Street Photo"
BorderWidth="1px"
Width="220px"
Height="180"
ImageUrl='<%# "PlaceImages/" + Eval("picPath") %>' />
</asp:HyperLink>
</ItemTemplate>
<SelectedItemStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
</asp:DataList>
以下是与上述代码链接的StreetPic.aspx页面:
<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile="~/App_Data/TravelJoansDB.accdb"
SelectCommand="SELECT * FROM [StreetPhotos] WHERE ([ID] = @ID)">
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="ID" Type="Int32" />
</SelectParameters>
</asp:AccessDataSource>
<table class="streetTableStyle">
<tr>
<td>
<asp:Image ID="Image1" runat="server" AlternateText="Street Picture" BorderWidth="1px" ImageUrl='<%# "PlaceImages/" + Eval("picPath") %>' />
</td>
</tr>
<tr>
<td>
<asp:Label ID="TextBox1" runat="server" Text='<%# Eval("picCaption") %>' />
</td>
</tr>
</table>
答案 0 :(得分:1)
您必须将表放入绑定到AccessDataSource
的formView中<asp:FormView ID="FormView1" runat="server" DataSourceID="AccessDataSource2">
<ItemTemplate>
<table class="streetTableStyle">
<tr>
<td>
<asp:Image ID="Image1" runat="server" AlternateText="Street Picture" BorderWidth="1px" ImageUrl='<%# "PlaceImages/" + Eval("picPath") %>' />
</td>
</tr>
<tr>
<td>
<asp:Label ID="TextBox1" runat="server" Text='<%# Eval("picCaption") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>