-
datagrid/datatable
Hi there. I was just testing and playing about, i have made a function which does something i need it to do. however it uses a datagrid/datatable to get the values from
is there another way of getting the values without having to show or use the datagrid?
Thanks!
-
You can use DataReader instead of Adapter and use ListView
Code:
SqlConnection cn=new SqlConnection("user id=sa;password=password;initial catalog=northwind");
private void Form1_Load(object sender, System.EventArgs e)
{
cn.Open();
SqlCommand cm=new SqlCommand("select * from territories",cn);
SqlDataReader dr=cm.ExecuteReader();
while(dr.Read())
{
ListViewItem li=listView1.Items.Add(dr[0].ToString());
li.SubItems.Add(dr[1].ToString());
li.SubItems.Add(dr[2].ToString());
}
cn.Close();
}