private void PopulateNames(object sender, PopulatingEventArgs e) { try { conn.Open(); List<string> types = new List<string>(); string accountQuery = "SELECT EmpName FROM EmpDetails WHERE EmpName LIKE '" + e.Parameter + "%'"; SqlDataReader accountTypes = null; SqlCommand query = new SqlCommand(accountQuery, conn); accountTypes = query.ExecuteReader(); while (accountTypes.Read()) { types.Add(accountTypes["EmpName"].ToString()); } AutoCompleteBox accountType = (AutoCompleteBox)sender; accountType.ItemsSource = types; accountTypes.Close(); conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); // Close the DB if there was an error. if (conn.State == ConnectionState.Open) conn.Close(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)