just o add to the question and futures similiar problems:
Do not use SQL as "insta-search" on textchanged proprieties. Its bad for many reasons as people mentioned above. But first of all, you can have problems by locking up SQL tables for having people trying so search something and generating alot of traffic as consequence, and even for one user, its unsafe and unfriendly to resources.. Besides, you have a high traffic for SQL injection. There are some good programming practices to make it safer, i'll try to elucidate a little more.
Okay, you already know this piece of information. But how the Correct way to do it?
Use objects, DAL and cache info until its old enough and have to update it.
How:
First things first, you should create a DAL/DAO class that is used ONLY for sql querys and operations. Do some search on the subject and why is a bad idea to have your business rules and sql code scrambled togheter. Here some short text about it:About DAL/DAO
Then, create a class of objects. For example: PersonelInfo. Wich contains every attribute that you need, like: name,documents, etc.
Here some info about objects handling: Using Objects with C#
After having your object nice and done, use lists to store and pass it to datatable or directly to datagridview if you wich.
List<Objectname> listname = new List<Objectname>();
Then, use some loop to iterate through SQL data and fill your list.
Example:
while(dataReader.Read())
{
Object objectname = new Object();
objectname.attribute1 = dataReadet["columname"].ToString();
objectname.attribute2 = dataReadet["columname"].ToString();
objectname.attribute3 = dataReadet["columname"].ToString();
listname.Add(objectname);
}
at the end return your objectlist:
Return listname;
That way you have full organized object list that you can:
- Use as base for cache. That list contains all information that user
needs to search for. Search the list with a foreach loop and return
desired values to the user. Just remember to update it when it gets
old.
- Use it as source for Datagridview or Datatable, its cheap.
- Use it with JSON, it can be sent by API or simple UDP/TCP connection
Hope this short comment bring you some light with data handling.
Note that not every data is safe to keep that way. Passwords and protected stuff should not be stored in memory or other ways that can be exploited.