Click here to Skip to main content
15,919,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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..............
Posted

You can refer here[^]
 
Share this answer
 
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();
 
Share this answer
 
v2
ListView1.datasource = object of SQLDataReader;
ListView1.Databind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900