Reputation: 5705
Here is my code:
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;
}
When I enter a letter in the textbox the datagrid become empty
Upvotes: 0
Views: 3563
Reputation: 427
never and I say never use == to compare 2 strings always use equals() or contains() if you are comparing 2 strings most likely u will get a false eventhough the 2 strings look exactly the same. The difference is that each of the string point to a different object. Basically everytime u make a string it creates a new object of the class String.
Upvotes: 0
Reputation: 60493
private void textBox1_TextChanged(object sender, EventArgs e)
{
var searchValue = textBox1.Text.Trim();//you can add a ToUpper();
var qry = (from p in dc.Products
where p.ProductName.StartsWith(searchValue);//you can add a ToUpper() to p.ProductName
select p).ToList();
productDataGridView.DataSource = qry;
}
Upvotes: 2