The search criteria comes from a CheckBox-List populated by database values [1,2,3,4,5,6...].
I want to be able to retrieve the selected checkbox values and include it into the WHERE
criteria of my SQL Command before executing it.
protected void Button1_Click(object sender, EventArgs e)
{
string checkedSkills = "";
//Store The checked values from chkBoxSkillset into a List.
List<ListItem> selected = new List<ListItem>();
foreach (ListItem item in chkBoxSkillset.Items)
if (item.Selected)
selected.Add(item);
string checkedSkills = "SELECT DISTINCT Student.*FROM Student" +
" INNER JOIN StudentSkillSet ON Student.StudentID =
StudentSkillSet.StudentID WHERE StudentSkillSet.SkillSetID IN ("
+ checkedSkills;
foreach (ListItem skill in selected)
{
checkedSkills+=Convert.ToString
(selected[Convert.ToInt16(skill)] + ",");
}
checkedSkills += ")";
}
Do i use cmd.Parameters or QueryString? How should i format it so it works?