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