Hi ,I've seen one of the articles here , named "Autosuggest TextBox From Database Column in Windows Forms" , and it was useful for me
but I want to create a TextBox that will suggest First names AND Last names from 2 SQL Server database columns FirstName & LastName.
I mean , if I typed A , it suggests me Anna, Amita ,.. (from first name column) and also Anderson , Armandi , ... (from the Family column)
thanks in advance
and I should say that I am a new member here :)
Wim SturkenboomPosted Sep 21, 2014, 2:21 PM
using (SqlConnection con = new SqlConnection(ConString))
{
SqlCommand cmd = new SqlCommand("SELECT FirstName FROM Employees", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
AutoCompleteStringCollection MyCollection = new AutoCompleteStringCollection();
while (reader.Read())
{
MyCollection.Add(reader.GetString(0));
}
cmd = new SqlCommand("SELECT LastName FROM Employees", con);
reader = cmd.ExecuteReader();
while (reader.Read())
{
MyCollection.Add(reader.GetString(0));
}
txtFirstName.AutoCompleteCustomSource = MyCollection;
con.Close();
}
Not tested, just copied and modified.