DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'userid'

a 夏天 提交于 2020-03-26 04:02:21

问题


I want to find the total number of active users who are members of the user table in my database. But I get an error like this:

DataBinding: 'System.Data.DataRowView' does not contain a property with name 'userid'

My code is as follows:

<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>

回答1:


The error means that there is no column named userid in the result from your query. And that makes sense since you are returning only one column. And you are not even naming that column with AS, so SQL makes it Expr1 as column name.

your query should be

SELECT COUNT(*) AS total_users FROM [user]

Now you can use the column name total_users in the Repeater

<h3><%#Eval("total_users") %></h3>


来源:https://stackoverflow.com/questions/46024579/databinding-system-data-datarowview-does-not-contain-a-property-with-the-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!