2014-02-05 32 views
0

我的WinForm應用程序中出現此錯誤:
不支持直接存儲查詢(DbSet,DbQuery,DbSqlQuery)的數據綁定。而是用數據填充DbSet,例如通過在DbSet上調用Load,然後綁定到本地數據。對於WPF綁定到DbSet.Local。對於WinForms綁定到DbSet.Local.ToBindingList()。

這是我的代碼:
ComboBox ValueMember Error

private DataBaseEntities entity = new DataBaseEntities(); 
categoryComboBox.DataSource = entity.TableName; 
categoryComboBox.DisplayMember = "Description"; 
//ProductType is the Primary Key of the table and is Identity as well 
//And when the compiler arrives here, the error is thrown 
categoryComboBox.ValueMember = "ProductType"; 



有人可以幫我解決我的錯誤?

回答

0

您不能直接將表格分配給網格。嘗試將其轉換爲這樣的列表

categoryComboBox.DataSource = entity.TableName.ToList(); 

這應該工作。

+0

謝謝你。它正在工作。我讀過一篇關於這個錯誤的文章,但還有一個例子。再次感謝@ElectricRouge。 –

相關問題