一个页面错误,我找了半天也不知是什么原因,请大虾指点
我的网面出现下面错误:
“System.Data.DataRowView”不包含名称为 WID 的属性。
我的网页代码部分如下:
SqlDataAdapter da=new SqlDataAdapter ( "select IID,IGname,IWNumber,IQuantity,IPrice,IProvider,IMangner,IHandler from [Irecords] ",cn);
//创建并填充DataSet
DataSet ds=new DataSet ();
da.Fill (ds);
in_storemanage.DataSource =ds;
in_storemanage.DataBind ();
cn.Close ();
控件代码:
<asp:datagrid id= "in_storemanage " runat= "server " Width= "100% " OnDeleteCommand= "DataGrid_Delete "
OnCancelCommand= "DataGrid_Cancel " OnEditCommand= "DataGrid_Edit " OnUpdateCommand= "DataGrid_Update " DataKeyField= "WID " AutoGenerateColumns= "False ">
<Columns>
<asp:BoundColumn DataField= "IID " ReadOnly= "True " HeaderText= "编号 "> </asp:BoundColumn>
<asp:BoundColumn DataField= "IGname " HeaderText= "货品名称 "> </asp:BoundColumn>
<asp:BoundColumn DataField= "IWNumber " HeaderText= "仓库编号 "> </asp:BoundColumn>
<asp:BoundColumn DataField= "IQuantity " HeaderText= "数量 "> </asp:BoundColumn>
<asp:BoundColumn DataField= "IPrice " HeaderText= "单价 "> </asp:BoundColumn>
<asp:BoundColumn DataField= "IProvider " HeaderText= "货品提供商 "> </asp:BoundColumn>
<asp:BoundColumn DataField= "IMangner " HeaderText= "收货人 "> </asp:BoundColumn>
<asp:BoundColumn DataField= "IHandler " HeaderText= "备注 "> </asp:BoundColumn>
<asp:EditCommandColumn ButtonType= "LinkButton " UpdateText= "更新 " CancelText= "取消 " EditText= "编辑 "> </asp:EditCommandColumn>
<asp:ButtonColumn Text= "删除 " CommandName= "Delete "> </asp:ButtonColumn>
</Columns>
</asp:datagrid>
请问这是什么原因?
------解决方案--------------------DataKeyField= "WID " 你定义了DataKey,但你的sql查询里并没有包括WID字段
------解决方案--------------------DataKeyField= "WID "
确实是有问题哦
错误提示明显指出了 你的查询里没有加入WID这个值 但是你却定义了这个的DataKeyField