這裏篩選的LINQ to SQL查詢是我的代碼:如何通過使用文本框輸入
private void textBox1_TextChanged(object sender, EventArgs e)
{
//**************************************
int aa = textBox1.Text.Length;
var qry = (from p in dc.Products
where p.ProductName.Substring(aa) == textBox1.Text.Trim()
select p).ToList();
productDataGridView.DataSource = qry;
}
當我在文字框中輸入一個字母DataGrid中成爲空
使用'p.ProductName.Contains(textBox1.Text.Trim())'而不是'p.ProductName.Substring(aa)== textBox1.Text.Trim()' – Chandu 2012-07-27 14:01:03
@Chandu p.ProductName.Contains textBox1.Text.Trim())意味着結果應該包含在文本框中的任何位置輸入的字母,我需要的是查詢返回的項目應該在文本框中有文本作爲第一個字符 – 2012-07-27 14:10:57