You create a DataGridView on the fly and set a DataSource for it. That's fine, but then you add a DataGridView to the layout collection's controls collection?
this.Controls.Add(dataGridView1);
By the way, the code is a little confused
String connection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\Tables.accdb;Persist Security Info=True"; string sql = "SELECT Clients FROM Tables"; using(OleDbConnection conn = new OleDbConnection(connection)) { conn.Open(); DataSet ds = new DataSet(); DataGridView dataGridView1 = new DataGridView(); using(OleDbDataAdapter adapter = new OleDbDataAdapter(sql,conn)) { adapter.Fill(ds); dataGridView1.DataSource = ds;
EDIT . After the comments below, it is clear that there is some confusion between the file name (TABLES.ACCDB) and the table name CLIENTS.
The SELECT statement is defined (in its basic form) as
SELECT field_names_list FROM _tablename_
therefore, the correct syntax used to retrieve all client data,
string sql = "SELECT * FROM Clients";
where * means β all fields present in the table
Steve
source share