i get two run time errors first({"Sequence contains more than one element"} ==> System.InvalidOperationException ) when there is more than once it occurred and also when i want to delete what i wrote in my textbox what should i do?
here is my code
private AutoCompleteStringCollection GetLinqDataSourceForString(string p)
{
var c = new AutoCompleteStringCollection();
c.Add( Getauto(p));
return c;
}
private void txtSearch_TextChanged(object sender, EventArgs e)
{
txtSearch.AutoCompleteSource = AutoCompleteSource.CustomSource;
txtSearch.AutoCompleteMode = AutoCompleteMode.Suggest;
txtSearch.AutoCompleteCustomSource = GetLinqDataSourceForString(txtSearch.Text);
}
and this one is in another layer to get info from data Base
public string AutoUpdate(string _search)
{
using (var context = new Phone_BookEntities1())
{
var c = (from d in context.Cantacts
where d.Cantact1.StartsWith(_search)
select d.Cantact1).SingleOrDefault();
return c;
}
}
Getauto(string ...)?where d.Cantact1.StartsWith(_search)is matching multiple items, hence Sequence contains more than one element.FirstOrDefault()instead ofSingleOrDefault().