c#中如何将数据库中查到的信息添加到listview中显示?
if(!dataReader.HasRows){MessageBox.Show("没有找到用户","结果提示",MessageBoxButtons.OK,MessageB...
if (!dataReader .HasRows )
{
MessageBox .Show ("没有找到用户","结果提示",
MessageBoxButtons .OK ,MessageBoxIcon.Information );
}
else
{
MessageBox.Show("sdfsdfsdf","sdfsdf",MessageBoxButtons .OK ,MessageBoxIcon.Information );
/*将查到的内容写到listview中
while (dataReader .Read ())
{
number=(string )dataReader ["number"];
name=(string )dataReader ["name"];
id=(string )dataReader ["id"];
address =(string )dataReader ["address"];
phone =(string )dataReader ["phone"];
admission_time =(string )dataReader ["admission_time"];
departments =(string )dataReader ["departments"];
classes =(string )dataReader ["classes"];
birthday =(string )dataReader ["birthday"];
//创建一个listview项
//ListViewItem lvistudent=new ListViewItem (number );
//将姓名放在Tag中
// lvistudent .Tag =(string )dataReader ["number"];
//向listview中添加一个新项
// listView1 .Items .Add (lvistudent );
//添加子项
//lvistudent .SubItems .AddRange (new string[]{name ,id ,address ,phone ,admission_time ,departments ,classes ,birthday });
}//White结束
*/ }//else 结束
不加成注释就直接跳到catch 显示查询出错,加成注释就能显示sdfsdfsdf,求助怎么更改 展开
{
MessageBox .Show ("没有找到用户","结果提示",
MessageBoxButtons .OK ,MessageBoxIcon.Information );
}
else
{
MessageBox.Show("sdfsdfsdf","sdfsdf",MessageBoxButtons .OK ,MessageBoxIcon.Information );
/*将查到的内容写到listview中
while (dataReader .Read ())
{
number=(string )dataReader ["number"];
name=(string )dataReader ["name"];
id=(string )dataReader ["id"];
address =(string )dataReader ["address"];
phone =(string )dataReader ["phone"];
admission_time =(string )dataReader ["admission_time"];
departments =(string )dataReader ["departments"];
classes =(string )dataReader ["classes"];
birthday =(string )dataReader ["birthday"];
//创建一个listview项
//ListViewItem lvistudent=new ListViewItem (number );
//将姓名放在Tag中
// lvistudent .Tag =(string )dataReader ["number"];
//向listview中添加一个新项
// listView1 .Items .Add (lvistudent );
//添加子项
//lvistudent .SubItems .AddRange (new string[]{name ,id ,address ,phone ,admission_time ,departments ,classes ,birthday });
}//White结束
*/ }//else 结束
不加成注释就直接跳到catch 显示查询出错,加成注释就能显示sdfsdfsdf,求助怎么更改 展开
1个回答
展开全部
ListViewItem listViewItem = new ListViewItem(number);
listViewItem.SubItems.Add(name);
listViewItem.SubItems.Add(id);
listViewItem.SubItems.Add(address);
listViewItem.SubItems.Add(phone);
listViewItem.SubItems.Add(admission_time);
listViewItem.SubItems.Add(departments);
listViewItem.SubItems.Add(classes);
listViewItem.SubItems.Add(birthday);
listView1.Items.Add(listViewItem);
listViewItem.SubItems.Add(name);
listViewItem.SubItems.Add(id);
listViewItem.SubItems.Add(address);
listViewItem.SubItems.Add(phone);
listViewItem.SubItems.Add(admission_time);
listViewItem.SubItems.Add(departments);
listViewItem.SubItems.Add(classes);
listViewItem.SubItems.Add(birthday);
listView1.Items.Add(listViewItem);
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询