Angel Princess

Angel Princess

  • NA
  • 100
  • 45.6k

Autosearch textbox

Mar 14 2014 2:39 AM
My Code  is:
textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
AutoCompleteStringCollection col = new AutoCompleteStringCollection();
sqlconn.Open();
string query = "select id from cmp_det where id =" + textBox1.Text;
SqlCommand command = new SqlCommand(query, sqlconn);
SqlDataReader sdr = command.ExecuteReader();
while (sdr.Read())
{
col.Add(sdr["Column_Name"].ToString());
}
sdr.Close();
textBox1.AutoCompleteCustomSource = col;
sqlconn.Close();
 
Sometime it works correctly  but sometime it gives error of "memory corrupt" in program.cs file when execute. also sometime it stops working with the error "Specified cast is not valid." Help me to solve these errors.
 
 

Answers (7)