SqlDataReader SqlDr = SqlCmd.ExecuteReader();//从库中读取数据
lv1.Items.Clear();
#region 建立列表
while (SqlDr.Read())
{
ListViewItem LVI = new ListViewItem();
LVI.SubItems[0].Text = SqlDr["字段1"].ToString();
LVI.SubItems.Add(SqlDr["字段2"].ToString());
LVI.SubItems.Add(SqlDr["字段3"].ToString());
lv1.Items.Add(LVI);//lv1是listview控件
}
#endregion
lv1.Items.Clear();
#region 建立列表
while (SqlDr.Read())
{
ListViewItem LVI = new ListViewItem();
LVI.SubItems[0].Text = SqlDr["字段1"].ToString();
LVI.SubItems.Add(SqlDr["字段2"].ToString());
LVI.SubItems.Add(SqlDr["字段3"].ToString());
lv1.Items.Add(LVI);//lv1是listview控件
}
#endregion
{
sqlDataAdapter1.Fill(dataSet21);
//添加列名
for(int i=0;i<dataSet21.Tables["authors"].Columns.Count;i++)
this.listView1.Columns.Add(dataSet21.Tables["authors"].Columns[i].ColumnName.ToString(),90,HorizontalAlignment.Left);
//添加行(数据库数据)
for(int j=0;j<dataSet21.Tables["authors"].Rows.Count;j++)
{
ListViewItem item=this.listView1.Items.Add(dataSet21.Tables["authors"].Rows[j][0].ToString());
for(int i=1;i<dataSet21.Tables["authors"].Columns.Count;i++)
item.SubItems.Add(dataSet21.Tables["authors"].Rows[j][i].ToString());
}
}