I have tabel for courses(CID,CName) and another table shows majors for each course CourseMajor(CID,MNom).

I have a drop dawn list which has majors numbers. if the user select a major number from the list another list should be filled of courses that are from the selected major.

I have the code below show me all courses not only the courses for the selected major number ! I used LIFT JOIN, RIGHT JOIN, INNER JOIN, FULL OUTER JOIN....and none of them work.

not: I am using C# asp.net vs.net...

 using (SqlConnection con = new SqlConnection(conStr))
        {
            using (SqlCommand cmd = new SqlCommand("SELECT * FROM TBCourse FULL JOIN TbCourseMajor ON  TBCourse.CId = TbCourseMajor.CId  AND TbCourseMajor.MNom = '" + DLMNom.SelectedValue + "' ", con))
            {
                con.Open();
                cmd.ExecuteNonQuery();
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    reader.Read();


                    while (reader.Read())
                    {
                     DLCName.Items.Add(new ListItem(reader["CName"].ToString(), reader["CNom"].ToString()));

                    }
                }
                else { TxtCRN.Text = "Not worked"; }
            }
        }

Related posts

Recent Viewed