我正在尝试检索特定于当前登录用户的数据库信息。
以下3行让我知道var1是正确的(因为它在页面上显示)
Dim var1 As String<Br>
var1 = LoginName1.Page.User.Identity.Name<br>
Response.Write(var1)
但是,当我尝试使用var1作为参数时它不起作用....只是想知道我错过了什么。
<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>
答案 0 :(得分:1)
您没有设置SqlDataSource的选择参数值。
Here's an overview包含使用参数的代码示例
答案 1 :(得分:0)
您需要为SqlDataSource
定义参数,然后进行设置。
即
<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>
然后在Page_Load
或类似的地方:
SqlDataSource1.SelectParameters("var1").DefaultValue = User.Identity.Name