gpt4 book ai didi

asp.net - 带有 Guid 参数的 SqlDataSource

转载 作者:行者123 更新时间:2023-12-02 10:52:29 24 4
gpt4 key购买 nike

我有这个sqlDataSource
@userId 是系统中当前用户的参数。

<asp:SqlDataSource ID="dsProfit" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="select name, sum(value) as suma  from AllProfitView where IdUser=@userId group by name  order by sum(value) desc">

</asp:SqlDataSource>

在代码后面,我在 Page_Load 中有这个:

 dsProfit.SelectParameters.Add("@userId", cui.getCurrentId());




public Guid getCurrentId()
{
MembershipUser currentUser = Membership.GetUser();
Guid currentUserId = (Guid)currentUser.ProviderUserKey;
return currentUserId;
}

当启动页面时,它会出现错误:必须声明标量变量“@userId”。

最佳答案

SelectParameter 添加到您的 sqlDataSource

<asp:SqlDataSource ID="dsProfit" runat="server"  
ConnectionString="<%$ ConnectionStrings:DefaultConnection %>"
SelectCommand="select name, sum(value) as suma from AllProfitView
where IdUser=@userId group by name order by sum(value) desc">
<SelectParameters>
<asp:Parameter Name="userId" Type="String" />
</SelectParameters>
</asp:SqlDataSource>

并像这样分配

  dsProfit.SelectParameters["userId"].DefaultValue =  
cui.getCurrentId().ToString();

关于asp.net - 带有 Guid 参数的 SqlDataSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17896539/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com