// 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.Collections; using System.Data; using MySql.Data.MySqlClient; namespace E { public class Rec { private int f1; private string f2; public Rec() : this(0, "") { } public Rec(int f1, string f2) { this.f1 = f1; this.f2 = f2; } public int F1 { get { return f1; } set { f1 = value; } } public string F2 { get { return f2; } set { f2 = value; } } public override string ToString() { return ("[" + f1 + "," + f2 + "]"); } } public class DataGateway { public static ArrayList GetAll() { MySqlConnection con = new MySqlConnection("Database=Test;Data Source=localhost;User Id=;Password="); con.Open(); MySqlCommand cmd = new MySqlCommand("SELECT F1,F2 FROM T1", con); ArrayList list = new ArrayList(); MySqlDataReader rdr = cmd.ExecuteReader(); while(rdr.Read()) { list.Add(new Rec((int)rdr[0], (string)rdr[1])); } rdr.Close(); con.Close(); return list; } } public class TestClass { public static void Main(string[] args) { ArrayList list = DataGateway.GetAll(); foreach(Rec r in list) { Console.WriteLine(r); } } } }