I am using Winforms for my application; SQL Server as Database
I want to know that whenever a text is typed in a text box, instant results are obtained from the SQL Server database tables for the received text.
For this, I have been given the following question:
Public Partial Sector Form 1: Form {SqlConnection conn = new SqlConnection (); Public form 1 () {conn.ConnectionString = "Trusted_Connection = true"; Conn.Open (); InitializeComponent (); } Private Zero Text box1_TextChanged (Object Sender, EventArgs e) {DataTable dt = null; SQL Commands CMD = New SQL Commands ("Select from item, where items like name '" + text box 1. text + "%'", Kon); SqlDataReader Reader = cmd.ExecuteReader (); Dt = new datatable (); Dt.load (reader); DataGridView1.DataSource = dt; }} But since it brings data from the database every time, it takes a lot of time, but I want a faster way, because I will use datasets for this purpose, because Datasets are used for disconnected environments.
OR
For the first time I will bring the whole ITEM table to a gridview with a database, and the amp; Display the form when the form is opened.
Now, when the text is inserted in the text box, it will not fetch data from the SQL database, but will search in gridview, will it be faster?
The way efficiently?
The item table has 3.4 million records.
How big is your item table?
If it is not large, then it will only store it in a dataset. Use the same text box, but do a search in a dataset.
If it is large, then I would recommend using a timer. Restart the timer, maybe 0.5 seconds on each lesson. When the timer has passed, then only query the database. This prevents multiple queries while typing the user.
Alternatively, if you can read the entire table and AutoCompleteCustomSource : Textbox1.AutoCompleteMode = Autocomplete mode. Recommendation; Foreach (DataRow line in dt.Rows) textBox1.AutoCompleteCustomSource.Add (line ["item_name"] as string);
Comments
Post a Comment