用listview显示数据库中信息
listview属性:this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3,
this.columnHeader4});
this.listView1.FullRowSelect = true;
this.listView1.GridLines = true;
this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.listView1.Location = new System.Drawing.Point(0, 0);
this.listView1.MultiSelect = false;
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(288, 208);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details;
private void button1_Click(object sender, System.EventArgs e)
{
string strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\\Person.mdb";
OleDbConnection conn = new OleDbConnection (strConn) ;
string strCommand="select * from Information";
conn.Open();
OleDbCommand cmd=new OleDbCommand(strCommand,conn);
OleDbDataReader reader=cmd.ExecuteReader();
while(reader.Read())
{
ListViewItem li=new ListViewItem();
li.SubItems.Clear();
li.SubItems[0].Text=reader["姓名"].ToString();
li.SubItems.Add(reader["年龄"].ToString());
li.SubItems.Add(reader["电话"].ToString());
li.SubItems.Add(reader["电子邮件"].ToString());
this.listView1.Items.Add(li);
}
reader.Close();
conn.Close();
}
这样就可以了。