I need to query a database of application titles and count the instances of each title. I've already got a list<string> of distinct values from a previous query, and now I need to count how many times each value occurs. I'm not sure if the query is correct, or how to handle the output. So far I have:
(cands is my list of distinct titles)
for (int i = 0; i < cands.Count; i++)
{
SqlCommand appCommand = new SqlCommand("select count(title) from poss_titles where title = @thisTitle", appConnection);
appCommand.Parameters.AddWithValue("@thisTitle", cands[i]);
SqlDataReader reader = appCommand.ExecuteReader();
I have created an 'AppTitle' class with getters and setters for 'name' and 'instances' so that I can return a List<AppTitle> from this method. Maybe there is a better way than this?