我有这个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”。
Type="Int32"
并将其转换为整数。我已经编辑了我的回答! - zey