// 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 { public int f1; public string f2; public Rec() : this(0, "") { } public Rec(int f1, string f2) { this.f1 = f1; this.f2 = f2; } } public class DataGateway2 { [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; } } }