I have a checkboxlist on my asp webpage which lists a number of skills required for a project. What i wish to do is to check multiple items from this checkboxlist and then create a search function to list all users who have the relevant skill to the ones checked. I can kinda get this to work, but instead of showing all users, it only shows one user.
For example, if i check "Planning" and "Designing" from my checkboxlist it should list users "Peter" and "Vicki" as they have the required skills but my code only shows Peter. My code is below:
StringBuilder sb2 = new StringBuilder();
foreach (ListItem item in chkGeneralSkills.Items)
{
if (item.Selected)
{
sb2.AppendFormat("{0} ", item.Text);
using (SqlConnection oConn = new SqlConnection(ConfigurationManager.ConnectionStrings["connString"].ToString()))
{
string sql = "SELECT us.FName + ' ' + us.SName As 'Name', " +
"sk.SkillsID, sl.SkillTitle " +
"FROM Users us " +
"LEFT JOIN Skills sk ON sk.UserID = us.UserID " +
"LEFT JOIN SkillsListing sl ON sl.SkillsListingID = sk.SkillsListingID " +
"WHERE sl.SkillTitle LIKE '" + item.Text + "'";
try
{
oConn.Open();
SqlCommand cmd = new SqlCommand(sql, oConn);
SqlDataReader reader = cmd.ExecuteReader();
chkMatchedUsers.DataTextField = "Name";
chkMatchedUsers.DataValueField = "Name";
chkMatchedUsers.DataSource = reader;
chkMatchedUsers.DataBind();
oConn.Close();
}
catch (Exception)
{
throw;
}
}
}
}