救命啊!listview显示数据报错...
这是我写的一个方法:
public void BindListView(string unitno)
{
SqlConnection connection = new SqlConnection(@"Server=.;uid=sa;pwd=123456;Database=test");
connection.Open();
SqlCommand commandtext = connection.CreateCommand();
commandtext.CommandText="select * from tb_item where unitno='"+unitno+"' ";
SqlDataReader dr = commandtext.ExecuteReader();
listView1.GridLines = true;
listView1.FullRowSelect = true;
listView1.View = View.Details;
listView1.Scrollable=true;
listView1.MultiSelect = false;
listView1.HeaderStyle = ColumnHeaderStyle.Clickable;
listView1.Visible = true;
while(dr.Read())
{
ListViewItem item = new ListViewItem();
item.SubItems.Clear();
item.SubItems[0].Text = dr["SerialNumber"].ToString();
item.SubItems[1].Text = dr["Barcode"].ToString();
item.SubItems[2].Text = dr["ItemCode"].ToString();
item.SubItems[3].Text = dr["ItemType"].ToString();
item.SubItems[4].Text = dr["SetDate"].ToString();
item.SubItems[5].Text = dr["OutDate"].ToString();
item.SubItems[6].Text = dr["Status"].ToString();
item.SubItems[7].Text = dr["DeliveryNO"].ToString();
item.SubItems[8].Text = dr["ReturnNO"].ToString();
item.SubItems[9].Text = dr["DocType"].ToString();
listView1.Items.Add(item);
}
}
这个方法是用来根据条件查询tb_item中的信息,然后将他显示到listview中,但是当程序运行到 item.SubItems[1].Text = dr["Barcode"].ToString();时报错,错误信息为:InvalidArgument=“1”的值对于“index”无效。
参数名: index
我找了半天也没找出来,请各位大虾帮忙找下...
public void BindListView(string unitno)
{
SqlConnection connection = new SqlConnection(@"Server=.;uid=sa;pwd=123456;Database=test");
connection.Open();
SqlCommand commandtext = connection.CreateCommand();
commandtext.CommandText="select * from tb_item where unitno='"+unitno+"' ";
SqlDataReader dr = commandtext.ExecuteReader();
listView1.GridLines = true;
listView1.FullRowSelect = true;
listView1.View = View.Details;
listView1.Scrollable=true;
listView1.MultiSelect = false;
listView1.HeaderStyle = ColumnHeaderStyle.Clickable;
listView1.Visible = true;
while(dr.Read())
{
ListViewItem item = new ListViewItem();
item.SubItems.Clear();
item.SubItems[0].Text = dr["SerialNumber"].ToString();
item.SubItems[1].Text = dr["Barcode"].ToString();
item.SubItems[2].Text = dr["ItemCode"].ToString();
item.SubItems[3].Text = dr["ItemType"].ToString();
item.SubItems[4].Text = dr["SetDate"].ToString();
item.SubItems[5].Text = dr["OutDate"].ToString();
item.SubItems[6].Text = dr["Status"].ToString();
item.SubItems[7].Text = dr["DeliveryNO"].ToString();
item.SubItems[8].Text = dr["ReturnNO"].ToString();
item.SubItems[9].Text = dr["DocType"].ToString();
listView1.Items.Add(item);
}
}
这个方法是用来根据条件查询tb_item中的信息,然后将他显示到listview中,但是当程序运行到 item.SubItems[1].Text = dr["Barcode"].ToString();时报错,错误信息为:InvalidArgument=“1”的值对于“index”无效。
参数名: index
我找了半天也没找出来,请各位大虾帮忙找下...
...全文
相关推荐
android PopupWindow显示ListView代码
以下将详细介绍如何使用Java源码在`PopupWindow`中显示`ListView`。首先,我们需要创建一个`ListView`,并为其设置数据源。
C#中,使用Thread新创建一个线程来查询数据库中的信息显示在控件“listView1”上,需要使用Invoke(代理名)方法来访问控件“listView1”,
#### 二、控件listView1的使用`listView1`是一个Windows Forms控件,用于显示列表数据。它可以以不同的视图模式显示数据,如图标、详细信息等。
android 项目 选项卡+滑动+listview 显示数据库中的信息
做的第一个项目吧 后来这个被 下拉菜单的替换掉了 这个我就保留了 里面实现了选项卡的滑动(有9个选项卡 3个一组 也算是选项卡的嵌套) listview 动态添加 查找 删除数据 退出 等功能 有
滑动删除Listview中的数据
在Adapter中,你需要维护一个数据集合,用于存储ListView要显示的数据。当用户滑动列表项时,你需要在Adapter中处理相应的删除逻辑。3.
ListView 下拉刷新 加载更多
当检测到下拉手势时,显示刷新动画,然后回调刷新数据的方法。二、加载更多(Load More)1. **基本概念**:加载更多是指当用户滚动到底部时,自动加载更多的数据到ListView中。


