Hello,
I've written the following code to show a query result in a datagrid, but I get an empty datagrid after the code is run!
Could you please tell me how I can fix the problem?
Do I need to assign the values to each row in the datagrind row by row using a loop?
Code:
OleDbConnection DBConnection = new System.Data.OleDb.OleDbConnection();
DBConnection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Chakaveh\Desktop\datagridTest\test1\dgt.accdb";
string SQL = "SELECT * FROM dgtest";
OleDbCommand cmd = new OleDbCommand(SQL,DBConnection);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable entries = ds.Tables[0];
dataGridView1.ReadOnly = true;
dataGridView1.DataSource = entries;
cmd.Dispose();
DBConnection.Close();
thank you