using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace auto_complete_textbox { public partial class Form1 : Form { public Form1() { InitializeComponent(); } AutoCompleteStringCollection ACSC = new AutoCompleteStringCollection(); private void textBox1_TextChanged(object sender, EventArgs e) { try { SqlCommand sqm = new SqlCommand("SELECT Location FROM DBO.Incident WHERE Location LIKE '%@Location%' ", new SqlConnection("data source=.;database=A police control system;uid=sa;pwd=sql")); sqm.Connection.Open(); sqm.Parameters.Add("@Location", SqlDbType.NVarChar).Value = textBox1.Text; SqlDataReader sdr = sqm.ExecuteReader(); if (sdr.HasRows == true) { while (sdr.Read()) { ACSC.Add(sdr["Location"].ToString()); } } sqm.Connection.Close(); textBox1.AutoCompleteMode = AutoCompleteMode.Suggest; textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource; textBox1.AutoCompleteCustomSource = ACSC; } catch (Exception ex) { messagebox.show(ex.message); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)