我使用实体框架将 Listview 绑定到我的数据库中有问题。 此代码仅显示表的第一行,但记录不要显示:
I have a problem with binding Listview to my database using Entity Framwork. This code only shows the first row of the table but the records do not show:
var item = (from p in db.tbl_film select p).FirstOrDefault(); string[] items = {item.flm_id.ToString(),item.flm_name,item.flm_description,item.flm_category }; foreach (var itemlist in items) { ListViewItem lvi = new ListViewItem(items); listView1.Items.Add(lvi); }我有一个表有几个记录。现在我想在ListView中显示它。
I have a table that has several records. Now I want to show it in the ListView.
表:flm_film
Table: flm_film
字段:flm_id,flm_name,flm_category
Fields: flm_id, flm_name, flm_category
我想在详细信息模式下在ListView中查看Entity Framework的数据。
I want to see data with Entity Framework in ListView in details mode.
推荐答案考虑这个代码:
var items = (from p in db.tbl_film select p).ToList(); foreach (var item in items) { // Create your ListViewItem here // Then add it to your listView here. }如果要检索多个记录,则不必使用 FirstOrDefault()因为正如你所说,你只得到第一个记录。
If you want to retrieve multiple records, you shouldn't have to use FirstOrDefault() because, as it says, you get only the first record.
更多推荐
将ListView绑定到数据库
发布评论