我正在创建一个会计/产品管理程序,并且代码有问题,应该在数据网格 View 中过滤数据库内容:
private void List(object sender, EventArgs e)
{
ObjectQuery<TblProduct> filteredProducts = new ObjectQuery<TblProduct>(
"SELECT VALUE P FROM TblProduct AS P WHERE P.ProductType = " + comboBox1.SelectedValue, salon);
dataGridView1.DataSource = filteredProducts;
}
而且我再次使用几乎相同的代码,因此可以做几乎相同的事情-对我的产品进行广告过滤并为每个产品创建按钮:
private void AddProductsToTabbedPanel()
{
foreach (TabPage tp in tabControl1.TabPages)
{
ObjectQuery<TblProduct> filProd = new ObjectQuery<TblProduct>("SELECTED VALUE P FROM TblProduct AS P", salon);
foreach (TblProduct tprod in filProd)
{
Button b = new Button();
b.Text = tprod.Description;
tp.Controls.Add(b);
}
}
}
在这两种情况下,我都遇到一个错误,告诉我EtitySqlException被拖延了,并且语法有些错误。
我从一个tutorial中获取了这些代码,所以我不明白为什么它不起作用...
最佳答案
在第二个示例中,您得到了
ObjectQuery<TblProduct> filProd = new ObjectQuery<TblProduct>("SELECTED VALUE P FROM TblProduct AS P", salon);
并且SELECTED是错误的。应该是SELECT
第一个似乎还可以。尝试更改并检查其是否运行
同样在本教程中,查询中的表是“TblProducts”而不是“TblProduct”。
关于c# - 使用ObjectQuery <T>进行过滤错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25291435/