// dgvGrid == DataGridView auf dem Formular private void btnOpen_Click(object sender, EventArgs e) { OdbcConnection conn = null; OdbcDataReader reader = null; try { // Verbindung herstellen conn = new OdbcConnection(@"dsn=MyDSN;UID=user;PWD=password;"); conn.Open(); // SQL-Kommando abschicken OdbcCommand cmd = new OdbcCommand("SELECT Names FROM MyTable", conn); // Daten einlesen reader = cmd.ExecuteReader(); // Bindingsource erstellen BindingSource bSource = new BindingSource(); // Reader an Source binden bSource.DataSource = reader; // Source an DataGridView übergeben dgvData.DataSource = bSource; } catch (Exception) { } finally { // aufräumen if (reader != null) reader.Close(); if (conn != null) conn.Close(); } }
- Weiterführender Link: Link