using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Data; using System.Data.OleDb; namespace WpfDBCnn1 { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { DataSet _myDS; public MainWindow() { InitializeComponent(); //C:\Local_WPF\MDB load_db(); } private void load_db() { OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=c:\\Local_WPF\\MDB\\pro2.mdb;"; conn.Open(); OleDbDataAdapter adapter = new OleDbDataAdapter ("SELECT DISTINCT Producer FROM WineProposal", conn); _myDS = new DataSet(); adapter.Fill(_myDS, "WineProposal"); MessageBox.Show("OK"); comboBox1.SelectedIndex = 0; label1.Content = ""; //adapter.TableMappings.Add("Table", "WineProposal"); foreach (DataRow row in _myDS.Tables["WineProposal"].Rows) { label1.Content += row["Producer"].ToString() + "\n"; comboBox1.Items.Add(row["Producer"].ToString()); listView1.Items.Add(row["Producer"].ToString()); } conn.Close(); } private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) { label2.Content = "Combobox Item : " + comboBox1.SelectedItem.ToString(); } private void listView1_SelectionChanged(object sender, SelectionChangedEventArgs e) { label2.Content = "ListBox Item : " + listView1.SelectedItem.ToString(); } } }