gpt4 book ai didi

asp.net - 你调用的对象是空的。

转载 作者:行者123 更新时间:2023-12-04 05:54:41 25 4
gpt4 key购买 nike

我下面的代码在编译时没有任何错误,但是当我打开页面时,在 Guid currentUserId = (Guid)currentUser.ProviderUserKey; 处发生错误。声明对象引用未设置为对象的实例。

foreach(DataRowView ProfileInfo in UserProfileDataSource.Select(DataSourceSelectArguments.Empty))
{
//Some codes where I display data from database
}



protected void UserProfileDataSource_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
MembershipUser currentUser = Membership.GetUser();

Guid currentUserId = (Guid)currentUser.ProviderUserKey;

e.Command.Parameters["USERID"].Value = currentUserId;
}

这是我的 SQLDataSource
<asp:SqlDataSource ID="UserProfileDataSource" runat="server" 
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
onselecting="UserProfileDataSource_Selecting"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"


SelectCommand="SELECT &quot;TITLE&quot;, &quot;FAMILYNAME&quot;, &quot;GIVENNAME&quot;, &quot;MIDDLENAME&quot;, &quot;POSITION&quot;, &quot;INSTITUTIONNAME&quot;, &quot;USERID&quot;, &quot;REGISTEREDDATE&quot; FROM &quot;MEMBERINFO&quot; WHERE (&quot;USERID&quot; = ?)">
<SelectParameters>
<asp:Parameter Name="USERID" Type="Object" />
</SelectParameters>
</asp:SqlDataSource>

厄尼

最佳答案

在尝试访问它之前,您应该检查以确保 currentUser 不为空:

if ( currentUser != null )
{
/* do stuff here */
}
else
{
/* do something else, like show an error message perhaps */
}

关于asp.net - 你调用的对象是空的。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9653606/

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