We have seen it on google, bing and other search engines that when you write a keyword or a pair of them the search box shows some related data to what you type. This can also be implemented in Sql database using C#.
To get this done we presume that there exists a database if you don’t know how to make a sql database in C# visit this page it shows you full steps of it.
Steps:
Step1: Drag and drop a textbox on C# form. Drag and drop a dataGridView on which your intellisense data will be displayed and updated accordingly.
Step2: Double click this textBox to get to coding side of textChange event.
Step3: In this event write this code
private void textBox1_TextChanged(object sender, EventArgs e)
{
string query = “select Emp_ID,Emp_Name,Father_Name,Email from Employee where Emp_Name like ‘” + textBox1.Text + “%’ ORDER BY Emp_Name ASC”;
using (SqlCommand comand = new SqlCommand(query, con))
{
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = comand;
DataTable ds = new DataTable();
ds.Locale = System.Globalization.CultureInfo.InvariantCulture;
da.Fill(ds);
dataGridView1.DataSource = ds;
}
}
Now in this code we have used a query which is the base for this intellisense property. What this query is doing is that it is selecting from Employee table all the important attributes of all employees whose names are like what you entered in textBox up till now.
Then after this Sql data adapter gets the data in it and gives it to dataGridView that we dropped on our form. This query uses a ‘like’ keyword and its self explanatory. Given below is a figure that shows this intellisense property as user types in characters on textBox. You can see that when only ‘s’ was typed there were more results but as we typed ‘sir’ the results converged and became more exact to what we are searching for in database. To download a complete working database with intellisense click here