Skip to content

Instantly share code, notes, and snippets.

@seanghay
Created May 11, 2018 16:03
Show Gist options
  • Save seanghay/820d052ac87911cc0ac03ec79d02705a to your computer and use it in GitHub Desktop.
Save seanghay/820d052ac87911cc0ac03ec79d02705a to your computer and use it in GitHub Desktop.
C# Connect To Access Database
try {
OleDbConnection connection = new OleDbConnection("provider=microsoft.ace.oledb.12.0;data source=C:\\Users\\Seanghay\\Documents\\Students.accdb");
connection.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter("select * from TableStudent", connection);
DataTable table = new DataTable();
adapter.Fill(table);
table.DefaultView.RowFilter = "Gender='male'";
dataGridView1.DataSource = table;
} catch(Exception ex) {
Console.WriteLine(ex.Message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment