本文介绍了如何使用SqlDataReader填充Listview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,亲爱的朋友,请告诉我如何将SqlDataReader数据添加到Listview的数据源中.我正在使用DataSet进行此操作,但是我想用SqlDataReader填充它,因为这将是从数据库中获取数据的最快方法.所以,请尽快给我答案...............
Hello Dear Friends Please tell me the way how can i add SqlDataReader Data to Listview''s DataSource. I am doing it with DataSet but I want to populate it with SqlDataReader bacause it will be the fastest way to fetch data from Database. So please give me Answer soon..............
推荐答案
SqlCommand cmd = new SqlCommand("commandText,con"); // here commandtext is your query or name of the procedure that will return the Rows and con is a SqlConnection object
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
ListViewItem obj=new ListViewItem(Convert.ToString(dr[0]),Convert.ToString(dr[1]);
//in object of ListViewItem give display member at first and give value member at second position
listView1.Items.Add(obj); // add object to the listbox
}
con.Close();
这篇关于如何使用SqlDataReader填充Listview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!