救命啊!listview显示数据报错...

danran251689 danran251689 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
这是我写的一个方法:
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
我找了半天也没找出来,请各位大虾帮忙找下...
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
danran251689
C# 111,128 成员 642,536 内容