frmjointables.cs
来自「移动设备的 LINQ 编程介绍 .NET Compact Framework 版」· CS 代码 · 共 55 行
CS
55 行
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Demo3___LinqToDataSet.NorthwindDataSetTableAdapters;
namespace Demo3___LinqToDataSet
{
public partial class FrmJoinTables : Form
{
private NorthwindDataSet northwindDataSet;
public FrmJoinTables()
{
InitializeComponent();
}
private void mniLoadData_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
northwindDataSet = new NorthwindDataSet();
using (CategoriesTableAdapter ta = new CategoriesTableAdapter())
{
ta.Fill(northwindDataSet.Categories);
}
using (ProductsTableAdapter ta = new ProductsTableAdapter())
{
ta.Fill(northwindDataSet.Products);
}
var selectedRows = from categoryRow in northwindDataSet.Categories
from productRow in northwindDataSet.Products
where categoryRow.Category_ID == productRow.Category_ID
orderby productRow.Product_ID
select new
{
ProductID = productRow.Product_ID,
ProductName = productRow.Product_Name,
Category = categoryRow.Category_Name,
UnitPrice = productRow.Unit_Price
};
dataGrid1.DataSource = selectedRows.ToList();
Cursor.Current = Cursors.Default;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?