<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:arqsi43ConnectionString %>" SelectCommand="SELECT [nome], [votos], [id] FROM [Playlist] WHERE ([semana_votacao] = @semana_votacao)">
<SelectParameters>
<asp:QueryStringParameter Name="semana_votacao"
QueryStringField="SELECT MAX(id) FROM VotacaoSemana" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
我有两张桌子 - PlayList
和VotacaoSemana
。
我需要在gridview上显示来自PlayList
的所有值,其属性semana_votacao
等于表votacaosemana
中的最大ID。
我使用向导尝试配置它,但我做错了,因为gridview是空的......
任何帮助?
答案 0 :(得分:1)
您无法为QueryStringField
url query string
编写SQL查询。更改SelectCommand
,如下所示no need to have parameters
SelectCommand = "SELECT [nome], [votos], [id] FROM [Playlist]
WHERE [semana_votacao] = (SELECT MAX(id) FROM VotacaoSemana)"