1

I am trying to retrieve database info that is specific to currently logged-in user.

The following 3 lines let me know that var1 is correct (As it displays it on the page)

Dim var1 As String<Br>
var1 = LoginName1.Page.User.Identity.Name<br>
Response.Write(var1)

But, when I try to use var1 as a parameter it is not working.... just wondered what I am missing.

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        SelectCommand="SELECT aspnet_Clubs.ClubName FROM aspnet_Clubs INNER JOIN aspnet_Users ON aspnet_Clubs.ClubID = aspnet_Users.ClubLinkID WHERE (aspnet_Users.UserName = @var1 )">
    </asp:SqlDataSource>
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
        BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" 
        CellPadding="2" DataSourceID="SqlDataSource1" ForeColor="Black" 
        GridLines="None" Height="50px" Width="274px">
        <AlternatingRowStyle BackColor="PaleGoldenrod" />
        <EditRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
        <Fields>
            <asp:BoundField DataField="ClubName" HeaderText="ClubName" 
                SortExpression="ClubName" />
        </Fields>
        <FooterStyle BackColor="Tan" />
        <HeaderStyle BackColor="Tan" Font-Bold="True" />
        <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" 
            HorizontalAlign="Center" />
    </asp:DetailsView>

2 Answers 2

1

You aren't setting the Select Parameter Value of your SqlDataSource.

Here's an overview with code-samples of working with Parameters

Sign up to request clarification or add additional context in comments.

Comments

0

You need to define the parameter for SqlDataSource and then set it.

i.e.

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        SelectCommand="SELECT aspnet_Clubs.ClubName FROM aspnet_Clubs INNER JOIN aspnet_Users ON aspnet_Clubs.ClubID = aspnet_Users.ClubLinkID WHERE (aspnet_Users.UserName = @var1 )">

<SelectParameters>
<asp:Parameter Name="var1" Type="String" />
</SelectParameters>
    </asp:SqlDataSource>

and then in Page_Load or similar do:

SqlDataSource1.SelectParameters("var1").DefaultValue = User.Identity.Name

2 Comments

thanks,, my application is MVC3 so i cannot see any code behind files to add the Page_Load function.. is there any way to code it into the individual page(s)?
I don't use MVC and only have a vague knowlege of it but I guess you'd put it in the Controller's constructor/ation method? Then MVC would use it to construct the page?

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.