string SQL = "SELECT departmentName FROM Department";
source.View = View.Details;
OleDbConnection con = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand(SQL, con);
OleDbDataReader r = null;
con.Open();
r = cmd.ExecuteReader();
for (int i = 0; i <= r.FieldCount - 1; i++)
{
source.Columns.Add("Column " + (i + 1).ToString(), 200, HorizontalAlignment.Left);
}
while (r.Read())
{
ListViewItem lvItem = new ListViewItem(r[0].ToString());
for (int i = 1; i <= r.FieldCount - 1; i++)
{
lvItem.SubItems.Add(r[i].ToString());
}
source.Items.Add(lvItem);
}
con.Close();