Well it doesn't look like you need the Subjects table at all, since Subject_Name is replicated in each table (why??) and you're not referring to any other data from the subjects table. I think your query simply needs to be "
Select courseoutcomes from CLO where SubjectName = @SubjectName
" (I've no idea why you break your
strQuery
into two separate strings...). That at least will give you the rows you need from the database. Then when you use your while... loop you will pick up each row and create an item in the dropdown. So your final code can be simplified to something like:
CheckBoxList1.Items.Clear();
String strConnString = ConfigurationManager.ConnectionStrings["facultylogConnectionString"].ConnectionString;
String strQuery = "select CourseOutcomes from CLO where SubjectName = @Subject_Name";
using (SqlConnection con = new SqlConnection(strConnString)) {
SqlCommand cmd = new SqlCommand();
cmd.Parameters.AddWithValue("Subject_Name", DropDownList1.SelectedItem.Value);
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader()) {
while (sdr.Read())
{
CheckBoxList1.Items.Add(new ListItem(sdr["CourseOutcomes"].ToString());
}
}
con.Close();
}
(I've typed the above straight into CP so may have got brackets unbalanced or made typos, hopefully you get the idea). As previously, if your code doesn't give you the results you want, then step through it in the debugger to understand WHY it's not doing what you expect. You say (about the data tables) "I'm not really sure what to do with them" ... then learn SQL, at least its basics, before you start programming with SQL databases. Experiment with SELECT queries in the environment of something like SSMS, or HeidiSQL, or even just link to the database with Access. Learn how relational databases work and get comfortable with SQL - it's not hard (at least not at this level!)
In the above I've dispensed with the try...catch block since you're not handling any exception anyway, so it really offers little other than, arguably, closing the connection in the "finally". As suggested above, I've put the connection in its own
using
block (and explicitly closed it when successful) as this will ensure it gets properly cleaned up whatever happens.