Hi Everyone,
I'm trying to create listview where column header name is retrieved from database (its number)
When i execute my code i get as column name System.Data.DataRow but it should be number from database.
My code is:
- SqlConnection con = new SqlConnection(@"Data Source=MAIN-PC\SQLEXPRESS;Integrated Security=True");
- SqlCommand cmd = new SqlCommand("USE "+comboBox1.Text+" ; Select StoreCode FROM stores",con);
- DataTable dt = new DataTable();
- con.Open();
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- da.Fill(dt);
- ListView view = new ListView();
- view.View = View.Details;
- listView1.Columns.Add("Store", 90, HorizontalAlignment.Left);
- foreach(DataRow row in dt.Rows)
- {
- listView1.Columns.Add(row.ToString(), 90, HorizontalAlignment.Left);
- }
Result is:

Rajanikant HawaldarRank #110 · 20.2K reputationPosted Apr 11, 2020, 7:53 AM EDT
Salman BegRank #284 · 8.8K reputationPosted Apr 11, 2020, 7:55 AM EDT