How to read values from datatable into listview?

WSDeveloper

New member
Joined
Apr 17, 2018
Messages
2
Programming Experience
Beginner
PIC.png


please see the picture, I want to show records in listview as they are saved in table.
but with below code it is reading group ids only and showing this in a single line.
C#:
  SqlDataAdapter dataAdap = new SqlDataAdapter(sqlcmd);

            DataTable data = new DataTable();
            dataAdap.Fill(data);
            if (data.Rows.Count > 0)
            {
                //---------------------------------

                foreach (DataRow row in data.Rows)
                {
                    ListViewItem item = new ListViewItem(row[0].ToString());
                    for (int i = 1; i < data.Columns.Count; i++)
                    {
                        item.SubItems.Add(row[i].ToString());
                        // item.Text = row[i].ToString();
                    }
                    listView1.Items.Add(item);
                }

                //------------------------
 
Without seeing what your sqlcmd looks like, it'll be very hard to help you. What if the sqlcmd has a TOP 1 or a WHERE clause that selects just one item from the database?
 
Back
Top Bottom