title: textbox search like in google
body: <p>I am using C#.net Windows form , and I need to create a search textbox which will display combo box values (similar to google search); The values displayed in the combo box will be values from the SQL 2005 database (example the user is searching on FirstName, the combobox will display all firstnames, which get filtered as the user types in more letters.... if user is searching on LastName, the combo box displays all LastName values in the database.. etc)</p>
  
  <p>when I am doing the above task </p>
  
  <p>I have written the sql query like this </p>
  
  <pre><code>SELECT  distinct(person_Firstname+''+person_Lastname) 
  AS 
  name FROM persondetails 
  WHERE name Like '%'+@name+'%'
  </code></pre>
  
  <p>when I am executing this query it gives error like this --- must declare a scalar varaible</p>
  
  <p>my aim is when i am entering first letter in textbox it will display all names starting with that letter like in google...</p>
  
  <p>can any one correct this ....</p>
  
  <pre><code>private void tbautocomplete_TextChanged(object sender, EventArgs e)
  {
      AutoCompleteStringCollection namecollection = new AutoCompleteStringCollection();
      SqlConnection con = new SqlConnection(@"Data Source=88888;Initial Catalog=contrynames;Integrated Security=True");
      SqlCommand cmd = new SqlCommand();
      cmd.Connection = con;
      cmd.CommandType = CommandType.Text;
      cmd.CommandText = "SELECT  distinct(person_Firstname+''+person_Lastname) AS name FROM persondetails WHERE name Like '%'+@name+'%'";
      con.Open();
      SqlDataReader rea = cmd.ExecuteReader();
      if (rea.HasRows == true)
      {
          while (rea.Read())
          namecollection.Add(rea["name"].ToString());            
      }
      rea.Close();
  
      tbautocomplete.AutoCompleteMode = AutoCompleteMode.Suggest;
      tbautocomplete.AutoCompleteSource = AutoCompleteSource.CustomSource;
      tbautocomplete.AutoCompleteCustomSource = namecollection;
  </code></pre>