frmsingletable.cs

来自「移动设备的 LINQ 编程介绍 .NET Compact Framework 版」· CS 代码 · 共 48 行

CS
48
字号
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 FrmSingleTable : Form
	{
		private NorthwindDataSet northwindDataSet;

		public FrmSingleTable()
		{
			InitializeComponent();
		}

		private void mniLoadData_Click(object sender, EventArgs e)
		{
			Cursor.Current = Cursors.WaitCursor;

			northwindDataSet = new NorthwindDataSet();
			using (ProductsTableAdapter ta = new ProductsTableAdapter())
			{
				ta.Fill(northwindDataSet.Products);
			}

			var selectedRows = from row in northwindDataSet.Products
							   where row.Category_ID == 1
							   orderby row.Product_ID descending
							   select row;

			/*DataSet dataSet = northwindDataSet;
			var selectedRows2 = from row in dataSet.Tables["Products"].AsEnumerable()
							   where row.Field<int>("Category ID") == 1
							   orderby row.Field<int>("Product ID") descending
							   select row;*/

			dataGrid1.DataSource = selectedRows.AsDataView();

			Cursor.Current = Cursors.Default;
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?