// 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.Linq; namespace E { public class MainClass { public static void Print(DataTable dt) { } public static void Main(string[] args) { OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Databases\MSAccess\Test.mdb;"); con.Open(); OleDbDataAdapter da = new OleDbDataAdapter("SELECT f1,f2 FROM t1", con); DataSet ds = new DataSet(); da.Fill(ds, "t1"); foreach(DataRow dr in ds.Tables["t1"].Rows) { Console.WriteLine(dr["f1"] + " " + dr["f2"]); } var q = ds.Tables["t1"].AsEnumerable().Where((dr) => (int)dr["f1"] > 2).OrderByDescending((dr) => (string)dr["f2"]); foreach(var dr in q) { Console.WriteLine(dr["f1"] + " " + dr["f2"]); } con.Close(); } } }