Asp.net SqlDataSource参数问题-使用loginName1作为sql参数
我正在尝试检索特定于当前登录用户的数据库信息 下面3行让我知道var1是正确的(因为它在页面上显示)Asp.net SqlDataSource参数问题-使用loginName1作为sql参数,asp.net,sql-server,parameters,sqldatasource,login-control,Asp.net,Sql Server,Parameters,Sqldatasource,Login Control,我正在尝试检索特定于当前登录用户的数据库信息 下面3行让我知道var1是正确的(因为它在页面上显示) Dim var1作为字符串 var1=LoginName1.Page.User.Identity.Name Response.Write(var1) 但是,当我尝试使用var1作为参数时,它不起作用。。。。只是想知道我错过了什么 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString=
Dim var1作为字符串
var1=LoginName1.Page.User.Identity.Name
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>
您没有设置SqlDataSource的Select参数值
对于使用参数的代码示例,您没有设置SqlDataSource的Select参数值
对于使用参数的代码示例您需要为
SqlDataSource
定义参数,然后进行设置
i、 e
然后在页面中加载或类似操作:
SqlDataSource1.SelectParameters(“var1”).DefaultValue=User.Identity.Name
您需要为SqlDataSource
定义参数,然后进行设置
i、 e
然后在页面中加载或类似操作:
SqlDataSource1.SelectParameters(“var1”).DefaultValue=User.Identity.Name
谢谢,我的应用程序是MVC3,因此我看不到添加页面加载功能的任何代码隐藏文件。。有没有办法将其编码到单独的页面中?我不使用MVC,对它只有模糊的了解,但我想你会将其放入控制器的构造函数/配置方法中?那么MVC将使用它来构建页面?谢谢,我的应用程序是MVC3,所以我看不到任何添加页面加载功能的代码隐藏文件。。有没有办法将其编码到单独的页面中?我不使用MVC,对它只有模糊的了解,但我想你会将其放入控制器的构造函数/配置方法中?那么MVC会用它来构建页面吗?
<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>
<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>