DataBinding: 'System.Data.DataRowView' 不包含名称为 'userid' 的 属性
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'userid'
我想在我的数据库中查找属于 user
table 成员的活跃用户总数。但是我得到这样的错误:
DataBinding: 'System.Data.DataRowView' does not contain a property with name 'userid'
我的代码如下:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<h3><%#Eval("userid") %></h3>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aytasarimConnectionString %>" SelectCommand="SELECT COUNT(*) FROM [user]"></asp:SqlDataSource>
该错误意味着您的查询结果中没有名为 userid
的列。这是有道理的,因为您只返回一列。而且您甚至没有用 AS
命名该列,因此 SQL 将其设为 Expr1
作为列名。
您的查询应该是
SELECT COUNT(*) AS total_users FROM [user]
现在您可以在 Repeater
中使用列名 total_users
<h3><%#Eval("total_users") %></h3>
我想在我的数据库中查找属于 user
table 成员的活跃用户总数。但是我得到这样的错误:
DataBinding: 'System.Data.DataRowView' does not contain a property with name 'userid'
我的代码如下:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<h3><%#Eval("userid") %></h3>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aytasarimConnectionString %>" SelectCommand="SELECT COUNT(*) FROM [user]"></asp:SqlDataSource>
该错误意味着您的查询结果中没有名为 userid
的列。这是有道理的,因为您只返回一列。而且您甚至没有用 AS
命名该列,因此 SQL 将其设为 Expr1
作为列名。
您的查询应该是
SELECT COUNT(*) AS total_users FROM [user]
现在您可以在 Repeater
中使用列名total_users
<h3><%#Eval("total_users") %></h3>