Use LINQ to SQL : SQL « LINQ « C# / CSharp Tutorial






using System;
using System.Linq;
using System.Data.Linq;
using System.Data.Linq.Mapping;

static class HelloLinqToSql {
    [Table(Name = "Contacts")]
    class Contact {
        [Column(IsPrimaryKey = true)]
        public int ContactID { get; set; }
        [Column(Name = "ContactName")]
        public string Name { get; set; }
        [Column]
        public string City { get; set; }
    }

    static void Main() {
        string path = System.IO.Path.GetFullPath("northwnd.mdf");
        DataContext db = new DataContext(path);

        var contacts =
          from contact in db.GetTable<Contact>()
          where contact.City == "Paris"
          select contact;

        foreach (var contact in contacts)
            Console.WriteLine("Bonjour " + contact.Name);
    }
}








22.75.SQL
22.75.1.Use LINQ to SQL