Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8339593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:55:27+00:00 2026-06-09T04:55:27+00:00

I create 3 classes then those 3 classes’s object create in another class. Now

  • 0

I create 3 classes then those 3 classes’s object create in another class. Now I want to read the data from the database.
My code is: I am retrieving the data from the database and call from the combo box.

       SqlConnection conn = MyDB.GetConnection();
       string selectStm = "SELECT c.CourseID,en.Score,s.StudentID FROM EnrollmentTable en,Course c,Student s WHERE en.StudentID = s.StudentID AND en.CourseID = c.CourseID";

       SqlCommand command = new SqlCommand(selectStm, conn);
       //command.Parameters.AddWithValue("@StudentID", StudentID);


       List<StudentScore> aStudentScore = new List<StudentScore>();

       StudentScore score = null;



       try
       {
           conn.Open();
           SqlDataReader reader = command.ExecuteReader();


           Enrollment enr = new Enrollment();

           while (reader.Read())
           {
               score = new StudentScore();



               score.EnrollmentData.StudentData.StudentID = reader["StudentID"].ToString();//Here is the problem.
               score.EnrollmentData.CourseData.CourseID = reader["CourseID"].ToString();//Here is the problem.

               score.Score = Convert.ToInt32(reader["Score"]);



               aStudentScore.Add(score);
           }

           reader.Close();
           return aStudentScore;
       }
       catch (SqlException ex)
       {
           throw ex;
       }
       finally
       {
           conn.Close();
       }

It doesn’t take any value….How can I do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:55:28+00:00Added an answer on June 9, 2026 at 4:55 am

    If your SELECT statement is not returning any rows, then there is a problem with your data. Either the EnrollmentTable.StudentID doesn’t match any records in the Student table or EnrollmentTable.CourseID doesn’t match any courses in the Course table.

    In any case, I tried to simplify the code so it would be easier to read:

    public class Student
    {
        string studentID = string.Empty;
        public string StudentID
        {get { return studentID;}
         set { studentID = value;}}
    };
    
    public class Course
    {
        string courseID = string.Empty;
        public string CourseID
        {get { return courseID;}
         set { courseID = value;}}
    };
    
    public class Enrollment
    {
        Student studentData = new Student();
        public Student StudentData
        {get { return studentData;}
         set { studentData = value;}
        }
        Course courseData = new Course();
        public Course CourseData
        {get { return courseData; }
         set { courseData = value; }}
    };
    
    public class StudentScore
    {
        Enrollment enrollmentData = new Enrollment();
        public Enrollment EnrollmentData
        {get { return enrollmentData;}
         set { enrollmentData = value;}}
    
        int score = 0;
        public int Score
        {get {return score;}
         set {score = value;}}
    };
    
    public List<StudentScore> getScoreList()
    {
        List<StudentScore> aStudentScore = new List<StudentScore>();
        StringBuilder tmpSQL = new StringBuilder();
        tmpSQL.Append("SELECT c.CourseID, en.Score, s.StudentID ");
        tmpSQL.Append("FROM EnrollmentTable en ");
        tmpSQL.Append("       INNER JOIN Student s ON en.StudentID = s.StudentID ");
        tmpSQL.Append("       INNER JOIN Course c ON en.CourseID = c.CourseID ");
        try
        {using (SqlConnection conn = MyDB.GetConnection()){
           conn.Open();
           using (SqlCommand command = new SqlCommand(tmpSQL.ToString(), conn)){
             using (SqlDataReader reader = command.ExecuteReader()){
               while (reader.Read())
                 {
                  StudentScore score = new StudentScore();
                  score.EnrollmentData.StudentData.StudentID = reader["StudentID"].ToString();
                  score.EnrollmentData.CourseData.CourseID = reader["CourseID"].ToString();
                  score.Score = Convert.ToInt32(reader["Score"]);
                  aStudentScore.Add(score);
                  };
                };
             };
          };
        }
        catch (Exception ex)
        {throw ex;}
        return aStudentScore; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I code in Python a lot, and I frequently create classes. Now, I'm not
I want to create classes Car, Vehicle, and Airplane with the following properties: Car
I'm using the Prototype.js (from www.prototypejs.org) library to create classes which are extended by
I want to use JavaCompiler to dynamically create some classes. I found the source
I want to search through all classes in a namespace for those containing a
I am using ORM to automatically create tables from model classes. I am naming
Let's say I release a code library as a standalone PHP class. Someone then
I would like to create a base class that all classes in my program
Still coming from C++ I find it cumbersome to create many small helper classes
Put simply about Table Data Gateway (TDG) implementation: you create separate TDG class that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.