// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Data; using System.Data.OleDb; using System.Drawing; using System.Windows.Forms; namespace DefaultNamespace { public class MainForm : Form { private ListBox listBox1; public MainForm() { InitializeComponent(); } [STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); } private void InitializeComponent() { listBox1 = new ListBox(); SuspendLayout(); listBox1.Location = new Point(50, 50); listBox1.Size = new Size(150, 300); OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Database\\MSAccess\\Test.mdb"); con.Open(); OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM T1", con); DataSet ds = new DataSet(); da.Fill(ds, "T1"); listBox1.DataSource = ds.Tables["T1"]; listBox1.DisplayMember = "F2"; listBox1.ValueMember = "F1"; ClientSize = new Size(250, 400); Controls.Add(listBox1); Text = "Listbox test"; ResumeLayout(false); } } }