// 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 System.Data.SqlClient; using System.Web.Services; namespace E { [Serializable] 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 class DataGateway { [WebMethod] public Rec[] GetAll() { SqlConnection con = new SqlConnection("server=ARNEPC3;Integrated Security=SSPI;database=Test"); con.Open(); SqlCommand cmd = new SqlCommand("SELECT F1,F2 FROM T1", con); ArrayList list = new ArrayList(); SqlDataReader rdr = cmd.ExecuteReader(); while(rdr.Read()) { list.Add(new Rec((int)rdr[0], (string)rdr[1])); } rdr.Close(); con.Close(); Rec[] res = (Rec[])list.ToArray(typeof(Rec)); return res; } } }