ASP.NET 2.0 framework
I'm trying to list all user related entries when the user visits the page. I have a session variable set with the visitor in session. Now I want to query the database with that ID. It seems to be executing, but no results are being returned (I'm displaying the contents in a seperate code section).
Please help!
<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
Don't use <asp:Parameter>
.You should be using <asp:SessionParameter>
to access the session variable directly:
<SelectParameters>
<asp:SessionParameter Name="VisitorID" SessionField="VisitorID" />
</SelectParameters>