DataBinding:“System.Data.Common.DataRecordInternal”不包含名为“XX”的属性(在线等待、、)
/// <summary>
/// 获取商品销售统计
/// </summary>
/// <returns></returns>
public SqlDataReader GetCardStasticInfo()
{
string commandText = "SELECT A.CardTypeId,B.CardTypeName,B.CardPrice,COUNT(A.CardTypeId) AS Num FROM dbo.[Card] AS A , dbo.CardType AS B GROUP BY A.CardTypeId,B.CardTypeId,B.CardTypeName,B.CardPrice HAVING A.CardTypeId=B.CardTypeId ORDER BY A.CardTypeId";
SqlConnection connection = new SqlConnection(_conString);
SqlCommand command = new SqlCommand(commandText,connection);
connection.Open();
return command.ExecuteReader(CommandBehavior.CloseConnection);
}
gridviewUI代码如下:
<asp:GridView
ID="grdCardStastic"
AutoGenerateColumns="false"
CssClass="grdCardStasticStyle"
HeaderStyle-CssClass="grdCardStastic_Header"
RowStyle-CssClass="grdCardStastic_Row"
PagerStyle-CssClass="grdCardStastic_Pager"
SelectedRowStyle-CssClass="grdCardStastic_Selected"
AllowPaging="true"
PageSize="5"
runat="server">
<Columns>
<asp:BoundField
HeaderText="物品名称"
DataField="CardTypeName"
ItemStyle-CssClass="columnStyle" />
<asp:BoundField
HeaderText="物品单价(元)"
DataField="CardPrice"
ItemStyle-CssClass="columnStyle" />
<asp:BoundField
HeaderText="总数量"
DataField="Num"
ItemStyle-CssClass="columnStyle" />
<asp:BoundField
HeaderText="售出量"
DataField="Num"
ItemStyle-CssClass="columnStyle" />
<asp:BoundField
HeaderText="剩余量"
DataField="Num"
ItemStyle-CssClass="columnStyle" />
</Columns>
<EmptyDataTemplate>
<br /><br />
<em>暂无相关记录!</em>
<br /><br />
</EmptyDataTemplate>
<PagerSettings
Mode="NextPreviousFirstLast"
FirstPageText="首页"
PreviousPageText="上一页"
NextPageText="下一页"
LastPageText="尾页" />
<PagerStyle
HorizontalAlign="Center" />
</asp:GridView>
运行后报错:DataBinding:“System.Data.Common.DataRecordInternal”不包含名为“CardTypeId”的属性
不知道什么原因,数据库中都查到了相关的数据,但用gridview绑定时总是报这个鬼错误。。 --------------------编程问答-------------------- SELECT A.CardTypeId as CardTypeId,B.CardTypeName as CardTypeName ,B.CardPrice as CardPrice....
以此类推
补充:.NET技术 , ASP.NET