C# QueryString—当参数为';未指定
我使用的是Visual Studio和C#,我有一个数据列表,可以显示我数据库中的游戏。我使用QueryString来确定要显示的流派(类别) 数据列表中填充了游戏标题和图像,我的SqlDataSource如下所示:C# QueryString—当参数为';未指定,c#,asp.net,query-string,C#,Asp.net,Query String,我使用的是Visual Studio和C#,我有一个数据列表,可以显示我数据库中的游戏。我使用QueryString来确定要显示的流派(类别) 数据列表中填充了游戏标题和图像,我的SqlDataSource如下所示: <asp:sqldatasource id="SqlDataSourceGames" runat="server" connectionstring="<%$ ConnectionStrings:gamesconstring %>" selectcomma
<asp:sqldatasource id="SqlDataSourceGames" runat="server" connectionstring="<%$ ConnectionStrings:gamesconstring %>"
selectcommand="SELECT uname, uimg
FROM games
INNER JOIN categories_games
ON games.uid = categories_games.uid
INNER JOIN consoles_games
ON games.uid = consoles_games.uid
WHERE consoleid = 2
AND categoryid = @categoryid">
<SelectParameters>
<asp:QueryStringParameter Name="categoryid" DbType ="String" Direction="Input" QueryStringField="categoryid" DefaultValue="" ConvertEmptyStringToNull="true" />
</SelectParameters>
</asp:sqldatasource>
这很好,我可以通过输入localhost/PS4.aspx?categoryid=1来指定流派。但是,如果没有指定categoryid,我希望显示所有类型。换句话说,当我转到localhost/PS4.aspx时
我尝试使用CancelSelectOnNullParameter=“false”
,但没有任何效果。使用
...
selectcommand="SELECT uname, uimg
FROM games
INNER JOIN categories_games
ON games.uid = categories_games.uid
INNER JOIN consoles_games
ON games.uid = consoles_games.uid
WHERE consoleid = 2
AND (categoryid = @categoryid OR @categoryid IS NULL)"
CancelSelectOnNullParameter="false">
使用
完美,正是我错过的。谢谢完美,正是我错过的。谢谢