I dont know if what i am asking is possible or not. That is why I am here to discuss .
I have a custom List that contains the information of all the users and their details.
On my application start I populate it from database. In other words it contains the copy of database. So instead of pulling data everytime from the database I want to perform operation on this list.
I wrote a query that searches users from database table and I want to translate it for this list so that my processing related to database is minimum. This is a single device application and no other user modifies the application.
List<Users> selectedUsers = new List<Users>();
sql_cmd = new SqlCommand();
sql_cmd.Connection = sql_con;
#region First Name Search
if (category == SearchCategory.ByFirstName)
{
sql_cmd.Parameters.Add("@firstName", SqlDbType.VarChar).Value = Value;
sql_cmd.CommandText = "SELECT * FROM AccountsUsers WHERE accFirstName Like @firstName+'%'";
SqlDataReader reader = sql_cmd.ExecuteReader();
if (reader.HasRows == true)
{
while (reader.Read())
{
Users userToAdd = new Users();
userToAdd.userId = int.Parse(reader["Id"].ToString());
userToAdd.firstName = reader["accFirstName"].ToString();
userToAdd.lastName = reader["accLastName"].ToString();
// GetAccountsDetails(userToAdd.userId, ref userToAdd);
selectedUsers.Add(userToAdd);
}
}
}
What i indend to do is search list that i have made not the database for the users.for example List contains many users and if in search box i enter ASthen I can filter out all entries Starting with AS.
Want similar functionality that query wild card does.
Pretty vague question. What is exactly your question? It is ofcourse possible to do everything in the program and send data to the database only on demand or application exit. There are several ways to do this.
The way you start is okay. You can alter users in any way you want and in the end you run throu them all again (or only those that have been change) and write a method to update them all to the database again.
[Edit]
Seeing your comment I assume you are talking about linq.
With Linq (System.Linq) you can alter, order, skip or take.. and such on lists.
When / where you want to apply ordering / sorting you can use stuff like
It’s best not to set the selectedList to this since you want to keep using it.
So to whatever datasource you set it. You can set it’s itemssource or datacontext to either of those above.