LINQ to SQL 第四集 - 如何取得 欄位 中 包含 某些特定字元的資料

如何取得 產品名稱 中 包含 ch 字元的資料,程式碼如下:

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 products = from p in db.Products
                           where p.ProductName.Contains("ch")
                           select p;

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

執行結果取得 產品名稱 中 包含 ch 字元的資料:

image

Enjoy.