Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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
share|improve this question
    
I'm looking for VB, not C# please. – Kana Jul 8 '16 at 21:42
    
You can take a look at marc_s' answer in the following post: stackoverflow.com/questions/17000390/…. – ConnorsFan Jul 8 '16 at 21:51
up vote 0 down vote accepted

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> 
share|improve this answer
    
Thanks Dennis. With your suggestion, I'm getting the following: Compiler Error Message: BC31143: Method 'Protected Sub SqlDataSource1_Selected(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)' does not have a signature compatible with delegate 'Delegate Sub SqlDataSourceSelectingEventHandler(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)'. – Kana Jul 9 '16 at 23:50
    
Remove the Selecting event handler completely.Set the session in the page load or on the previous page and access it using the example I provided.Have a look at this example - forums.asp.net/t/… it exactly the way ecbruck suggests – Denys Wessels Jul 10 '16 at 5:42
    
Thanks Dennis. Removed the Selecting event handler completely. And the session is being set on the pageLoad. Session("VisitorID") = userID Now getting: Parser Error Message: The server tag is not well formed. Source Error: Line 15: <asp:SqlDataSource Line 16: ID="UserReports" Line 17: runat="server" – Kana Jul 10 '16 at 11:13
    
That means one of the controls in your .aspx page is not well formed(doesn't have a closing tag,has an invalid character e.t.c) inspect your .aspx page and find the problem.And remember to mark my post as answered if it helped you – Denys Wessels Jul 10 '16 at 11:37
    
Thank you Denis. I was able to get the parse error corrected and now able to see the results with the following: <asp:Repeater id="Repeater1" DataSourceId="SQLsourceUserReports" Runat="server"> <ItemTemplate> <asp:HyperLink id="HyperLink1" Text='<%# Eval("ReportName") %>' NavigateUrl='<%# Eval("ReportPath", "{0}") %>' runat="server" /> </ItemTemplate> </asp:Repeater> The reason I had Selecting event handler was because I wanted to track the user clicks on the links above. Can you please help? – Kana Jul 10 '16 at 18:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.