数据绑定:“System.Data.DataRowView"不包含名为“ProductID"的属性 [英] DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'ProductID'

查看:17
本文介绍了数据绑定:“System.Data.DataRowView"不包含名为“ProductID"的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,我已将下拉列表与数据集正确绑定,但出现此错误:我的代码是:

Friends i have properly bind the dropdown with dataset but it is giving this error: my codes are:

绑定数据集

 DataSet ds = new ViewAction().GetAllProductInfoData();
            ddlprdctname.DataSource = ds;
            ddlprdctname.DataTextField = "ProductName";
            ddlprdctname.DataValueField ="ProductID";
            ddlprdctname.DataBind();

和 GetAllProductInfoData() 函数是

and GetAllProductInfoData() function is

 public DataSet GetAllProductInfoData()
        {
            SqlCommand cmd = DataConnection.GetConnection().CreateCommand();
            cmd.CommandText = "Select ProductID ProductName,SubCategory2ID,CompanyID,Price,Quantity,Description from ProductInfo";
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            cmd.Dispose();
            DataConnection.CloseConnection();
            return ds;
        }

是什么错误请帮我解决

推荐答案

您的查询中 ProductID 后缺少逗号.正如所写的那样,将 ProductName 理解为 ProductID 返回的列名别名,而不是您最有可能想要的单独列.

You are missing a comma in your query after ProductID. As written, it is understanding ProductName to be the returned column name alias for ProductID, and not a separate column as you most likely intended.

您所写的查询相当于:

Select ProductID AS ProductName, SubCategory2ID, ...

这篇关于数据绑定:“System.Data.DataRowView"不包含名为“ProductID"的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆