title: Textbox autocomplete with MySQL
body: <p>I am trying to do the text box autocomplete by using the code below, but it gives the error </p>
  
  <pre><code>ERROR :"Object reference not set to an instance of an object"
  </code></pre>
  
  <p>on this line:</p>
  
  <pre><code>for (int count = 0; count &lt; dt.Rows.Count; count++)
  </code></pre>
  
  <p>Can anyone please help me?   </p>
  
  <pre><code>private void tbMemberName_TextChanged_1(object sender, EventArgs e)
  {
      tbMemberName.AutoCompleteMode = AutoCompleteMode.Suggest;
      tbMemberName.AutoCompleteSource = AutoCompleteSource.CustomSource;
      AutoCompleteStringCollection namec = new AutoCompleteStringCollection();
  
      //string search ="%"+ tbMemberName.Text +"%";
      //string @Name = tbMemberName.Text; 
      String sql =
          @"SELECT DISTINCT(member_Firstname +''+ member_Lastname) AS Name FROM members WHERE Name  Like '%'+tbMemberName.Text+'%'";
      DataTable dt = MemberFormHelper.GetData(sql, mf);
      if (dt.Rows.Count &gt;= 0)
      {
          for (int count = 0; count &lt; dt.Rows.Count; count++)
          {
              namec.Add(dt.Rows[count][Name].ToString());
          }
      }
      tbMemberName.AutoCompleteCustomSource = namec;
  }
  </code></pre>