【发布时间】:2011-08-19 11:26:13
【问题描述】:
我有一个
table product with colums product_id
prodcut_name
category_id
another table category
category_id
category_name
我正在使用运行良好的 datagridview 填充这些产品详细信息
我需要在 datagridview 中获取所选行的类别名称,因为我已经这样做了......
private void productGridview_Cellclick(object sender, DataGridViewCellEventArgs e)
{
string productname = Convert.ToString(selectedRow.Cells["productnam"].Value);
var categoryids = from cats in abc.products
where cats.product_Name.Equals(productname)
select cats.category_Id;
var catogynames = from categorytypes in abc.categories
where categorytypes.category_Name.Equals(categoryids)
select categorytypes.category_Name;
string categorynames = catogynames;
}
得到一个
error : cannot implicitly convert type sysytem.linq.iqueryble<string> to string ...
我需要做什么才能在 productgridview productnam 列中获取选定单元格的单个类别名称
任何建议..请..
非常感谢....
修改后的代码: 出错了:
not supported exception:
Unable to create a constant value of type 'System.Object'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.
【问题讨论】:
标签: c# winforms linq entity-framework linq-to-entities