将ListView绑定到数据库

编程入门 行业动态 更新时间:2024-10-25 10:32:13
本文介绍了将ListView绑定到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用实体框架将 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绑定到数据库

本文发布于:2023-10-16 00:37:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1495958.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   数据库   ListView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!