Ricardo Neves
Ricardo Neves

Reputation: 515

'where' clause datasource on c#

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

I have 2 tables - PlayList and VotacaoSemana.

I need to show on a gridview all values from PlayList that have the attribute semana_votacao equal to the max id from table votacaosemana.

I used the wizard to try to configure it, but I am doing something wrong, because the gridview is empty...

Any Help?

Upvotes: 0

Views: 734

Answers (1)

Kaf
Kaf

Reputation: 33839

You cannot write sql queries for QueryStringField which is url query string. Change your SelectCommand as follows and no need to have parameters

SelectCommand = "SELECT [nome], [votos], [id] FROM [Playlist] 
WHERE [semana_votacao] = (SELECT MAX(id) FROM VotacaoSemana)"

Upvotes: 1

Related Questions