textBox1.AutoCompleteMode = AutoCompleteMode.Suggest; textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource; AutoCompleteStringCollection DataCollection2 = new AutoCompleteStringCollection(); getData2(DataCollection2); textBox1.AutoCompleteCustomSource = DataCollection2;
private void getData2(AutoCompleteStringCollection dataCollection) { try { string customer= "Customer"; string connetionString = null; SqlConnection connection; SqlCommand command; SqlDataAdapter adapter = new SqlDataAdapter(); DataSet ds = new DataSet(); connetionString = System.Configuration.ConfigurationSettings.AppSettings["connection"]; string sql = "SELECT [party_name] FROM [Party_details] where party_name like '%" +textBox1.Text+ "%'"; connection = new SqlConnection(connetionString); try { connection.Open(); command = new SqlCommand(sql, connection); adapter.SelectCommand = command; adapter.Fill(ds); adapter.Dispose(); command.Dispose(); connection.Close(); foreach (DataRow row in ds.Tables[0].Rows) { dataCollection.Add(row[0].ToString()); } } catch (Exception ex) { MessageBox.Show("Can not open connection ! "); } } catch (Exception trt) { } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)