ASP.NET 2.0框架SqlDataSource - 带会话变量过滤器的SelectCommand
我试图列出用户访问该页面时所有与用户相关的条目。我在会话中设置了访问者的会话变量。现在我想用该ID查询数据库。它似乎正在执行,但没有返回结果(我在单独的代码部分显示内容)。
请帮忙!
<asp:SqlDataSource
ID="UserReports"
runat="server"
ConnectionString= "<%$ ConnectionStrings:MyConnectionString %>"
SelectCommand = "SELECT [ID], [ReportName], [ReportPath] FROM [Pan].
[dbo].[Reports] WHERE ([VisitorID] = @VisitorID)"
OnSelecting = "SqldsExample_Selecting">
<SelectParameters>
<asp:Parameter Name="VisitorID" Type="String"/>
</SelectParameters>
</asp:SqlDataSource>
On the code behind:
Sub SqldsExample_Selecting(sender As Object, e As
SqlDataSourceSelectingEventArgs)
UserReports.SelectParameters.Add("@VisitorID", Session("VisitorID"))
End Sub
我要找的VB,不C#请。 – Kana
你可以看看marc_s的答案在下面的帖子中:http://stackoverflow.com/questions/17000390/assiging-parameters-to-sqldatasource。 – ConnorsFan