1

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
2
  • I'm looking for VB, not C# please. Commented Jul 8, 2016 at 21:42
  • You can take a look at marc_s' answer in the following post: stackoverflow.com/questions/17000390/…. Commented Jul 8, 2016 at 21:51

1 Answer 1

2

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> 
Sign up to request clarification or add additional context in comments.

8 Comments

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)'.
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
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"
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
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?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.