C# 读取DataSet数据并显示在ListView控件中

            /*lvStudentList为ListView控件名 */         

            DataSet ds = new DataSet();
            ds = student.QueryStudents();     //查询表的信息
            int rowCount, columnCount,i,j;
            rowCount = ds.Tables[0].Rows.Count;
            columnCount = ds.Tables[0].Columns.Count;

            lvStudentList.BeginUpdate();
            lvStudentList.Items.Clear();
            string[] lvitem = new string[columnCount];
            for (i = 0; i < rowCount; i++)
            {
                for (j = 0; j < columnCount; j++)
                {
                    lvitem[j] = ds.Tables[0].Rows[i][j].ToString();
                }
                ListViewItem lvi = new ListViewItem(lvitem);
                lvStudentList.Items.Add(lvi);
            }
            lvStudentList.EndUpdate();

 

你可能感兴趣的:(ListView,String,C#,dataset)