Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net SqlDataSource参数问题-使用loginName1作为sql参数_Asp.net_Sql Server_Parameters_Sqldatasource_Login Control - Fatal编程技术网

Asp.net SqlDataSource参数问题-使用loginName1作为sql参数

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=

我正在尝试检索特定于当前登录用户的数据库信息

下面3行让我知道var1是正确的(因为它在页面上显示)

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>