Welcome to MSDN Blogs Sign in | Join | Help

LINQ to SQL 第五集 - 如何比對日期欄位的資料

取得訂單日期為 1998 年的資料,當然也可以比對 月(Month)  或  日(Day)。

using System;
using System.Linq;
using System.Windows.Forms;

namespace LinqToSql
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            NorthwindDataContext db = new NorthwindDataContext();

            var q = from o in db.Orders
                           where o.OrderDate.Value.Year == 1998
                           select o;

            dataGridView1.DataSource = q.ToList();
        }
    }
}

執行結果:

image

Enjoy.

Published Thursday, September 25, 2008 7:08 PM by jchiou
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# car insurance » LINQ to SQL ????????? - ?????????????????????????????????

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker