Hi,
Below code will get the data from access database and show it to the grid. Please modify the mdb path and file name and also modify the select query.
private void button1_Click(object sender, EventArgs e)
{
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data source= C:\myAccessFile.mdb";
try
{
conn.Open();
string sqlQuery = "select * from table";
OleDbDataAdapter da = new OleDbDataAdapter(sqlQuery, conn);
DataTable dtTable = new DataTable();
da.Fill(dtTable);
dataGridView1.DataSource = dtTable;
}
catch (Exception ex)
{
MessageBox.Show("Failed to connect to data source");
}
finally
{
conn.Close();
}
}
Best Regards,
Muthuraja