// 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 ComboBox comboBox1; public MainForm() { InitializeComponent(); } [STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); } private void InitializeComponent() { comboBox1 = new ComboBox(); SuspendLayout(); comboBox1.Location = new System.Drawing.Point(50, 50); comboBox1.Size = new System.Drawing.Size(150, 25); 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"); comboBox1.DataSource = ds.Tables["T1"]; comboBox1.DisplayMember = "F2"; comboBox1.ValueMember = "F1"; ClientSize = new Size(250, 400); Controls.Add(comboBox1); Text = "Combobox test"; ResumeLayout(false); } } }