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 }}用[循环] INSERT ……
for(i=0i<listview行数,i++)
{
insert into talbe (id,name)
values(listview的id和name列的值)
}
【注】
//取得listview某行某列的值
ListView1.Items.Item[1].SubItems.GetText)
listview1.Items[i].SubItems.strings[0]
1楼的我没用过~
以下是我自己使用的方法:
绑定LISTVIEW的方法如下:
string[] str = new string[5]//获取列数
if (this.dsDish.Tables["getDish"].Rows.Count >0)//判断数据集中是否有数据;getDish为数据集dsDish中的数据表,默认的表的索引为0开始
{
for (int i = 0i <= this.dsDish.Tables["getDish"].Rows.Count - 1i++)
{
str[0] = this.dsDish.Tables["getDish"].Rows[i][0].ToString()
str[1] = this.dsDish.Tables["getDish"].Rows[i][1].ToString()
str[2] = this.dsDish.Tables["getDish"].Rows[i][2].ToString()
str[3] = this.dsDish.Tables["getDish"].Rows[i][3].ToString()
ListViewItem lvi = new ListViewItem(str, 0)
this.listView1.Items.Add(lvi)
}
}
使用的时候只需要将数据集dsDish改为自己的数据集,列数改为自己的在LISTVIEW中显示的列数,将数据集集中的表改为自己在数据集中定义的表(如果没定义就将改为 0 即可)
评论列表(0条)