'where'子句数据源在c#上

时间:2012-12-08 12:52:04

标签: c# sql-server datasource where

<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>

我有两张桌子 - PlayListVotacaoSemana

我需要在gridview上显示来自PlayList的所有值,其属性semana_votacao等于表votacaosemana中的最大ID。

我使用向导尝试配置它,但我做错了,因为gridview是空的......

任何帮助?

1 个答案:

答案 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)"