I am trying to select data from the database to listview, but it is not working .There are no errors or anything but the code is totally unresponsive.....
private void Form1_Load(object sender, EventArgs e)
{
listView1.View = View.Details;
listView1.GridLines = true;
listView1.FullRowSelect = true;
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
con.ConnectionString = @"Data Source=.;Initial Catalog=ListView_Data;Integrated Security=True";
cmd.CommandText = @"select ProductName,Price,Quantity from producttable";
con.Open();
cmd.Connection = con;
da.SelectCommand = cmd;
da.Fill(dt);
//////////////////////////////////////////////////////////////////////
string[]ar=new string[100];
for (int i = 0; i < dt.Rows.Count; i++)
{
ar[i] = dt.Rows[0][i].ToString();
}
ListViewItem itm = new ListViewItem(ar);
listView1.Items.Add(itm);
}
ar[i] = dt.Rows[0][i].ToString();and check what happen?