C#C
C#3y ago
bernie2024

❔ ✅ How to call a specific attribute from a getter class to another class

Hey there, I am struggling to call this attribute from another class. The two relevant code pieces are:

public List<CompletedAssignment> GetCompletedAssignments(int studentID, int assignmentID)
        {
            List<CompletedAssignment> completedAssignments = new List<CompletedAssignment>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string query = "SELECT StudentID, AssignmentID, EarnedPoints FROM CompletedAssignments WHERE StudentID = @StudentID AND AssignmentID = @AssignmentID";
                SqlCommand command = new SqlCommand(query, connection);
                command.Parameters.AddWithValue("@StudentID", studentID);
                command.Parameters.AddWithValue("@AssignmentID", assignmentID);

                connection.Open();

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        CompletedAssignment completedAssignment = new CompletedAssignment();

                        completedAssignment.StudentID = reader.GetInt32(0);
                        completedAssignment.AssignmentID = reader.GetInt32(1);
                        completedAssignment.EarnedPoints = reader.GetInt32(2);

                        completedAssignments.Add(completedAssignment);
                    }
                }
            }

            return completedAssignments;
        }



and
Was this page helpful?