C#listview 怎么才能读取多行数据

C#listview 怎么才能读取多行数据,第1张

用循环把数据插入进ListView,用reader方法读取中括号中的字段名。

lv1.Items.Clear()//清空lv1中的记录

ListViewItem li = new ListViewItem()

li.SubItems.Clear() //清空每行数据的每一列数据。

foreach (DataRow reader in stu.Rows) //前提是stu有数据,stu是DataTable

{

ListViewItem item = new ListViewItem((reader["EMP_NO"]).ToString())

item.SubItems.Add(reader["NAME"].ToString())

item.SubItems.Add(reader["ID"].ToString())

this.lv1.Items.Add(item)

namespace ShopModel{public class Shops{string shopname double Price int number int allnumber int singlenumber public string Shopname{get { return shopname}set { shopname = value}}public double Price1{get { return Price}set { Price = value}}public int Number{get { return number}set { number = value}} public int Allnumber{get { return allnumber}set { allnumber = value}}public int Singlenumber{get { return singlenumber}set { singlenumber = value}} }}查询所有数据private static IList<Shops>Getnumber(){string sql = "select * from Shop" List<Shops>list = new List<Shops>() using(DataTable dt = DBHelper.GetDataSet(sql)){foreach(DataRow row in dt.Rows ){Shops shop = new Shops() shop.Shopname =(string)row["SpName"] shop.Number =(int)row["SpNumber"] shop.Price1 = Convert.ToDouble( row["SpPrice"]) shop.Allnumber = (int)row["SpAllnumber"] shop.Singlenumber = (int)row["Spsinglenumber"] list.Add(shop) }return list }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9901967.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存