I'm new to Visual Studio 2010 C# and MySQL. I am creating an application where there is a part in there that will show all the information in the database(MySQL) in a listview in c#. I already created the adding part of the data in the database. I have some codes in here but it doesn't work, no information is shown in my listview.
This is the code:
listViewCompany.Items.Clear(); string cmd = "select company_name, company_other_names, company_contactperson, company_contactperson_position from company"; DBConn db = new DBConn(); DataTable tbl = db.retrieveRecord(cmd); int x = 0; foreach (DataRow row in tbl.Rows) { ListViewItem lv = new ListViewItem(row[0].ToString()); lv.SubItems.Add(row[1].ToString()); lv.SubItems.Add(row[2].ToString()); lv.SubItems.Add(row[3].ToString()); listViewCompany.Items.Add(lv); }
tbl.Rows. Check its.Countproperty if there are any rows returned.