Exemplo n.º 1
0
        private void dgvGroup_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            northwindEntities dc      = new northwindEntities();
            string            Country = Convert.ToString(dgvGroup.Rows[e.RowIndex].Cells[0].Value);
            var query = from c in dc.Customers
                        where c.Country == Country
                        select c;

            dgvDetails.DataSource = query.ToList();
        }
Exemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 這行程式碼會將資料載入 'northwindDataSet.Customers' 資料表。您可以視需要進行移動或移除。
            this.customersTableAdapter.Fill(this.northwindDataSet.Customers);
            // TODO: 這行程式碼會將資料載入 'northwindDataSet.Customers' 資料表。您可以視需要進行移動或移除。
            this.customersTableAdapter.Fill(this.northwindDataSet.Customers);
            //select Country, Count(*) from Customers group by Country
            northwindEntities dc = new northwindEntities();
            //var query = (from c in dc.Customers
            //             group c by c.Country into CountryGroup
            //             select new
            //             {
            //                 國家 = CountryGroup.Key,
            //                 人數 = CountryGroup.Count()
            //             }).OrderByDescending(group => group.人數);
            var query = dc.Customers.GroupBy(c => c.Country).Select(CountryGroup => new
            {
                家  = CountryGroup.Key,
                人數 = CountryGroup.Count()
            }).OrderByDescending(g => g.人數);

            dgvGroup.DataSource = query.ToList();
        }